/* css/pages/market-analysis.css
   Public Market Analysis (PMA) page — responsive two-column layout.
   Depends on: site-theme.css, layout.css
*/

/* ── Layout: two-column on desktop, stacked on mobile ── */
.pma-layout {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 900px) {
  .pma-layout {
    grid-template-columns: 1fr;
  }
}

/* ── Map container ── */
.pma-map-wrap {
  position: sticky;
  top: 72px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

#pmaMap {
  height: 520px;
  width: 100%;
  border-radius: var(--radius-lg);
}

@media (max-width: 900px) {
  .pma-map-wrap { position: static; }
  #pmaMap { height: 360px; }
}

@media (max-width: 640px) {
  #pmaMap { height: 260px; }
}

/* ── Controls bar (buffer selector) ── */
.pma-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}

.pma-controls label {
  font-size: var(--small);
  font-weight: 600;
  color: var(--text);
}

.pma-controls select,
.pma-controls input[type="number"] {
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-size: var(--small);
  font-family: var(--font-sans);
}

.pma-controls select:focus,
.pma-controls input[type="number"]:focus {
  outline: none;
  box-shadow: var(--focus-ring);
}

.pma-map-hint {
  padding: 0.4rem 1rem;
  font-size: var(--tiny);
  color: var(--faint);
  background: var(--card);
  border-top: 1px solid var(--border);
}

/* ── Analysis Panel ── */
.pma-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.pma-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.25rem;
}

.pma-card h2 {
  font-size: var(--h3);
  font-weight: 700;
  margin-bottom: 0.6rem;
}

.pma-card h3 {
  font-size: var(--small);
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Site Score ── */
.pma-score-wrap {
  display: flex;
  align-items: center;
  gap: 1.1rem;
}

.pma-score-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  border: 3px solid var(--accent);
  color: var(--text-strong);
  background: var(--accent-dim);
  flex-shrink: 0;
}

.pma-score-meta {
  flex: 1;
}

.pma-score-label {
  font-size: var(--tiny);
  color: var(--faint);
  margin-bottom: 0.2rem;
}

.pma-score-tier {
  font-size: var(--small);
  font-weight: 700;
}

/* ── Radar chart ── */
.pma-radar-wrap {
  position: relative;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
}

/* ── Dimension bars ── */
.pma-dim-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.5rem;
}

.pma-dim-item {
  display: grid;
  grid-template-columns: 1fr auto 50px;
  align-items: center;
  gap: 0.5rem;
}

.pma-dim-name {
  font-size: var(--tiny);
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.pma-dim-info {
  font-size: .65rem;
  color: var(--faint);
  cursor: help;
  flex-shrink: 0;
  line-height: 1;
}

.pma-dim-bar-wrap {
  height: 6px;
  background: var(--bg2);
  border-radius: 99px;
  overflow: hidden;
}

.pma-dim-bar {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.4s ease;
}

.pma-dim-score {
  font-size: var(--tiny);
  font-weight: 700;
  text-align: right;
  color: var(--text);
}

/* ── Risk flags ── */
.pma-flags {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.pma-flag {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: var(--tiny);
  padding: 0.3rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}

.pma-flag-ok   { background: var(--good-dim); border-color: var(--good); color: var(--good); }
.pma-flag-warn { background: var(--warn-dim); border-color: var(--warn); color: var(--warn); }
.pma-flag-bad  { background: var(--bad-dim);  border-color: var(--bad);  color: var(--bad); }

/* ── LIHTC supply / capture ── */
.pma-stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.pma-stat {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
}

.pma-stat-value {
  font-size: 1.2rem;
  font-weight: 750;
  color: var(--text-strong);
  line-height: 1.1;
}

.pma-stat-label {
  font-size: var(--caption);
  color: var(--faint);
  margin-top: 0.15rem;
}

/* ── AMI mix inputs ── */
.pma-ami-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.pma-ami-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.pma-ami-field label {
  font-size: var(--caption);
  color: var(--faint);
}

.pma-ami-field input[type="number"] {
  width: 100%;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-size: var(--small);
}

/* ── Export buttons ── */
.pma-export-bar {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.pma-btn {
  padding: 0.45rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: var(--small);
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background 0.15s;
}

.pma-btn:hover {
  background: var(--bg2);
}

.pma-btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.pma-btn-primary:hover {
  background: var(--accent-dim);
  color: var(--accent);
}

/* ── Empty / loading states ── */
.pma-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--faint);
  font-size: var(--small);
}

.pma-loading {
  color: var(--faint);
  font-size: var(--small);
  padding: 0.5rem 0;
}

/* ── Map legend (Leaflet bottom-left control) ── */
.pma-legend {
  background: var(--card, #fff);
  border: 1px solid var(--border, rgba(0,0,0,.12));
  border-radius: var(--radius-sm, 4px);
  padding: 0.4rem 0.6rem;
  font-size: 11px;
  color: var(--text, #1a1a2e);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-width: 180px;
  line-height: 1.4;
}

.pma-legend-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 3px;
}

.pma-legend-circle {
  border-radius: 50%;
  width: 10px;
  height: 10px;
}

/* ── Tooltip for map overlays ── */
.pma-tooltip {
  background: var(--card, #fff);
  border: 1px solid var(--border, rgba(0,0,0,.12));
  border-radius: 4px;
  padding: 3px 7px;
  font-size: 11px;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
  color: var(--text, #1a1a2e);
}

/* ── Data Quality Banner ── */
.pma-quality-banner {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  margin-bottom: 1rem;
  font-size: var(--tiny);
}

.pma-quality-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pma-quality-label {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.pma-quality-pill {
  font-weight: 700;
  white-space: nowrap;
}

.pma-confidence-badge {
  display: inline-flex;
  align-items: center;
  font-weight: 700;
  white-space: nowrap;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: var(--tiny);
  cursor: help;
  transition: opacity 0.15s;
}
.pma-confidence-badge:hover { opacity: 0.85; }
.pma-confidence-badge.confidence-high   { background: var(--good-dim); color: var(--good); }
.pma-confidence-badge.confidence-medium { background: var(--warn-dim); color: var(--warn); }
.pma-confidence-badge.confidence-low    { background: var(--bad-dim);  color: var(--bad);  }

.pma-freshness-badge {
  font-weight: 600;
  white-space: nowrap;
}

.pma-quality-warnings {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border);
}

.pma-quality-warn-item {
  color: var(--warn);
  font-size: var(--tiny);
  margin-bottom: 0.2rem;
}

/* ── Benchmarking ── */
.pma-benchmark-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.pma-benchmark-percentile {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

.pma-benchmark-percentile sup {
  font-size: 0.8rem;
  vertical-align: super;
}

.pma-benchmark-label {
  flex: 1;
}

/* ── Benchmarking / Pipeline comparison table ── */
.pma-bench-table {
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.pma-bench-table thead tr {
  background: var(--bg2);
}

.pma-bench-table tbody tr:hover {
  background: var(--bg2);
}

/* ── Report section navigation (sticky horizontal pill nav) ── */
.ma-section-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin-bottom: 1.5rem;
}

.ma-section-nav::-webkit-scrollbar { display: none; }

.ma-section-nav-list {
  display: flex;
  gap: 0;
  list-style: none;
  padding: 0;
  margin: 0;
  white-space: nowrap;
}

.ma-section-nav-link {
  display: block;
  padding: 0.6rem 1rem;
  font-size: var(--small);
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.ma-section-nav-link:hover,
.ma-section-nav-link.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Report sections ── */
.ma-report-section {
  margin-bottom: 2.5rem;
  scroll-margin-top: 3.5rem;
}

.ma-report-section > h2 {
  font-size: var(--h2);
  font-weight: 700;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
  color: var(--text-strong);
}

/* ── KPI card grid (executive summary) ── */
.ma-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.ma-kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ma-kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text-strong);
}

.ma-kpi-label {
  font-size: var(--tiny);
  color: var(--faint);
}

.ma-kpi-card.good  { border-left: 4px solid var(--good); }
.ma-kpi-card.warn  { border-left: 4px solid var(--warn); }
.ma-kpi-card.bad   { border-left: 4px solid var(--bad); }

/* ── Narrative block ── */
.ma-narrative {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  font-size: var(--small);
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 1rem;
}

/* ── Data table ── */
.ma-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.ma-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--small);
}

.ma-table thead th {
  background: var(--bg2);
  font-weight: 700;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: var(--tiny);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.ma-table tbody td {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.ma-table tbody tr:last-child td { border-bottom: none; }
.ma-table tbody tr:hover { background: var(--bg2); }

/* ── Score pill / badge ── */
.ma-score-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  padding: 0.2rem 0.5rem;
  border-radius: 99px;
  font-size: var(--tiny);
  font-weight: 700;
}

.ma-score-pill.high     { background: var(--good-dim); color: var(--good); }
.ma-score-pill.moderate { background: var(--warn-dim); color: var(--warn); }
.ma-score-pill.low      { background: var(--bad-dim);  color: var(--bad);  }

/* ── Section placeholder ── */
.ma-section-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
  color: var(--faint);
  font-size: var(--small);
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ── Component score bar (6-component model) ── */
.ma-component-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

@media (max-width: 600px) {
  .ma-component-grid { grid-template-columns: 1fr; }
}

.ma-component-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
}

.ma-component-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.ma-component-name {
  font-size: var(--tiny);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ma-component-score {
  font-size: var(--small);
  font-weight: 800;
  color: var(--text-strong);
}

.ma-component-bar-wrap {
  height: 5px;
  background: var(--bg2);
  border-radius: 99px;
  overflow: hidden;
}

.ma-component-bar {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.4s ease;
}

/* ── Opportunity band chip ── */
.ma-opportunity-chip {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 99px;
  font-size: var(--tiny);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ma-opportunity-chip.high     { background: var(--good-dim); color: var(--good); }
.ma-opportunity-chip.moderate { background: var(--warn-dim); color: var(--warn); }
.ma-opportunity-chip.lower    { background: var(--bad-dim);  color: var(--bad);  }

/* ── Mobile: single column for report sections ── */
@media (max-width: 600px) {
  .ma-kpi-grid { grid-template-columns: 1fr 1fr; }
  .ma-report-section > h2 { font-size: var(--h3); }
}

/* ── PMA method tabs ── */
.pma-method-bar { margin-bottom: 1rem; }

.pma-method-tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.pma-tab {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0.35rem 0.9rem;
  font-size: var(--small);
  min-height: 44px;        /* WCAG 2.5.5 touch target */
  min-width: 44px;
  transition: background 0.15s, border-color 0.15s;
}

.pma-tab:hover:not(.pma-tab--active) { background: var(--border); }

.pma-tab--active {
  background: var(--accent) !important;
  color: #fff !important;
  border-color: var(--accent) !important;
}

/* ── Progress bar ── */
#pmaProgressWrap { margin-top: 0.75rem; }

#pmaProgressBar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

#pmaProgressFill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
  will-change: width;
}

/* ── Justification card ── */
#pmaJustificationNarrative {
  white-space: pre-wrap;
  font-size: 0.8em;
  line-height: 1.65;
  max-height: 260px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.85rem;
  color: var(--text);
}

/* ── Intro text — full-width justified ── */
.pma-intro-text {
  font-size: 1rem;
  line-height: 1.65;
  text-align: justify;
  hyphens: auto;
  text-wrap: pretty;
  color: var(--text);
}
.pma-intro-text + .pma-intro-text { margin-top: 0.35rem; }
.pma-intro-note {
  font-size: .82rem;
  color: var(--muted);
  text-align: justify;
  hyphens: auto;
  text-wrap: pretty;
  margin-top: 0.35rem;
}

/* ── Map layer controls ── */
.map-layer-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.85rem;
  margin-top: 0.6rem;
}
.map-layer-section + .map-layer-section { margin-top: 0.5rem; }

.map-layer-heading {
  font-size: var(--small);
  font-weight: 700;
  color: var(--text);
  display: block;
  margin-bottom: 0.35rem;
}

.map-layer-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.6rem;
}

.map-layer-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: var(--small);
  color: var(--text);
  cursor: pointer;
  padding: 0.25rem 0.5rem 0.25rem 0.3rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  min-height: 44px;
  transition: background .12s ease, border-color .12s ease;
}
.map-layer-label:hover {
  background: color-mix(in oklab, var(--accent) 8%, var(--card) 92%);
  border-color: color-mix(in oklab, var(--accent) 25%, var(--border) 75%);
}

/* Custom checkbox styled as a toggle pill */
.map-layer-cb {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border);
  border-radius: 3px;
  background: var(--bg2);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition: background .12s ease, border-color .12s ease;
}
.map-layer-cb:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.map-layer-cb:checked::after {
  content: '';
  position: absolute;
  top: 2px; left: 4px;
  width: 5px; height: 8px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}
.map-layer-cb:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ── MLS listings layer badge ── */
.map-layer-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0 5px;
  border-radius: 8px;
  background: var(--muted, #546e7a);
  color: #fff;
  vertical-align: middle;
  margin-left: 3px;
  line-height: 1.5;
}
.map-layer-badge--ok   { background: var(--good,  #2e7d32); }
.map-layer-badge--warn { background: var(--warn,  #f57c00); }
.map-layer-cb:disabled { opacity: .4; cursor: not-allowed; }
label:has(.map-layer-cb:disabled) { opacity: .6; cursor: not-allowed; }

/* ── Layer picker ── */
#pmaLayerPickerWrap {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
}

/* ── Inline field-error messages (Audit 5.2) ── */
.field-error {
  display: block;
  font-size: 0.8rem;
  color: var(--bad, #dc2626);
  margin-top: 0.25rem;
}
.field-error[hidden] {
  display: none;
}

/* ── Mobile touch targets for controls ── */
@media (max-width: 900px) {
  .pma-controls select {
    min-height: 44px;
  }

  .map-layer-details summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.5rem 0;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* ================================================================
   Site Comparison Table
   ================================================================ */
.sc-table-wrap { margin-top: 0.5rem; }
.sc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}
.sc-table th {
  text-align: left;
  font-weight: 700;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 6px 8px;
  border-bottom: 2px solid var(--border-strong);
  white-space: nowrap;
}
.sc-table td {
  padding: 8px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.sc-table tbody tr:hover { background: var(--bg2); }
.sc-row--best td { background: color-mix(in oklab, var(--card) 80%, var(--good) 8%); }
.sc-site-label {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.sc-site-coords {
  font-size: .72rem;
  color: var(--faint);
}
.sc-band {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: .75rem;
  font-weight: 700;
  white-space: nowrap;
}
.sc-band--high     { background: var(--good-dim); color: var(--good); }
.sc-band--moderate  { background: var(--warn-dim); color: var(--warn); }
.sc-band--lower     { background: var(--bad-dim);  color: var(--bad);  }
.sc-dim-bar { margin-top: 2px; }
.sc-remove-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.sc-remove-btn:hover { background: var(--bad-dim); color: var(--bad); }
.sc-save-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}
