/* =========================================================
   NYC Community District Explorer — Bloomberg Visual Language
   ========================================================= */

:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-body: 16px;
  --text-md: 20px;
  --text-lg: 28px;
  --text-xl: 44px;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-bold: 700;

  --leading-tight: 1.1;
  --leading-snug: 1.3;
  --leading-body: 1.5;

  --bg-page: #ffffff;
  --bg-subtle: #f6f6f4;

  --rule-light: #d4d4d1;
  --rule-strong: #1a1a1a;

  --ink-primary: #1a1a1a;
  --ink-secondary: #4a4a48;
  --ink-tertiary: #7a7a77;

  --accent: #f9ca00;
  --accent-on: #1a1a1a;

  --positive: #00875a;
  --negative: #cc2b2b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-page);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: var(--leading-body);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

/* ── Page shell ──────────────────────────────────────────── */

.page-shell {
  max-width: 1300px;
  margin: 0 auto;
  padding: 20px 40px 56px;
}

/* ── Page header — kicker / headline / deck ─────────────── */

.page-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 32px;
  align-items: start;
  padding-bottom: 20px;
}

.page-header-title {
  /* left column */
}

.kicker {
  margin-bottom: 10px;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-primary);
}

.page-headline {
  max-width: 20ch;
  margin-bottom: 14px;
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
  color: var(--ink-primary);
}

.page-deck {
  max-width: 52ch;
  font-size: var(--text-body);
  font-weight: var(--weight-regular);
  line-height: var(--leading-snug);
  color: var(--ink-secondary);
}

/* intro collapses when a district is selected */
#page-intro.is-collapsed {
  display: none;
}

/* 2px near-black rule between header and map+panel */
.page-divider {
  border: none;
  border-top: 2px solid var(--rule-strong);
  margin: 0 0 8px;
}

/* ── Mode toggle — typographic, yellow underline ────────── */

.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding-top: 2px;
}

.mode-toggle-divider {
  display: inline-block;
  width: 1px;
  height: 12px;
  background: var(--rule-light);
  font-size: 0;
  color: transparent;
  flex-shrink: 0;
}

.mode-button {
  position: relative;
  min-width: 0;
  padding: 0 0 4px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--ink-tertiary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  letter-spacing: 0.01em;
  transition: opacity 150ms ease;
}

.mode-button:hover {
  color: var(--ink-primary);
  opacity: 0.7;
}

.mode-button.is-active {
  color: var(--ink-primary);
  opacity: 1;
}

.mode-button.is-active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
}

/* ── Choropleth chips — typographic, yellow underline ────── */

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 24px;
  padding: 2px 0 10px;
}

.chip-row.is-hidden {
  display: none;
}

.metric-chip {
  position: relative;
  padding: 0 0 4px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--ink-tertiary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: opacity 150ms ease;
}

.metric-chip:hover {
  color: var(--ink-primary);
  opacity: 0.7;
}

.metric-chip.is-active {
  color: var(--ink-primary);
}

.metric-chip.is-active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
}

/* ── Two-column layout ───────────────────────────────────── */

.layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 40px;
  align-items: start;
  margin-top: 12px;
}

.map-column {
  position: sticky;
  top: 4px;
}

/* ── Map ─────────────────────────────────────────────────── */

.map-meta {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 8px;
}

.map-label-text {
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: -0.01em;
  color: var(--ink-primary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.map-zoom-hint {
  margin-top: 5px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: 0.02em;
  color: var(--ink-tertiary);
  text-align: right;
}

/* Map on white with 1px near-black border */
.map-frame {
  position: relative;
  padding: 0;
  border: 1px solid var(--rule-strong);
  background: none;
}

#district-map {
  display: block;
  width: 100%;
  height: auto;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

#district-map *:focus,
#district-map *:focus-visible,
#district-map [tabindex]:focus,
#district-map [tabindex]:focus-visible {
  outline: none !important;
}

.district-label {
  fill: rgba(26, 26, 26, 0.55);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.01em;
  pointer-events: none;
  user-select: none;
}

.map-legend-area {
  margin-top: 10px;
}

.legend.is-hidden {
  display: none;
}

.legend-caption {
  margin-bottom: 6px;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-tertiary);
}

.legend-scale {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  margin-bottom: 4px;
}

.legend-swatch {
  height: 9px;
}

.legend-labels {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
  color: var(--ink-tertiary);
  text-align: center;
}

/* ── Detail panel — flush, no card ──────────────────────── */

.detail-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
}

.panel-empty-hint {
  margin-top: 24px;
}

.panel-empty-prompt {
  margin-bottom: 10px;
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  line-height: 1.4;
  color: var(--ink-primary);
}

.panel-empty-body {
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  line-height: 1.6;
  color: var(--ink-secondary);
}

.section-block {
  margin-bottom: 0;
}

/* 1px near-black rule between sections */
.section-block + .section-block {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--rule-strong);
}

/* ── Panel tabs ──────────────────────────────────────────── */

.tab-nav {
  display: flex;
  margin-top: 12px;
  border-bottom: 2px solid var(--rule-light);
}

.tab-button {
  position: relative;
  flex: 1;
  padding: 6px 4px 10px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--ink-tertiary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  letter-spacing: 0.01em;
  text-align: center;
  cursor: pointer;
  transition: color 150ms ease;
}

.tab-button:hover {
  color: var(--ink-primary);
}

.tab-button.is-active {
  color: var(--ink-primary);
  font-weight: var(--weight-bold);
}

.tab-button.is-active::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
}

.tab-panel {
  display: none;
  padding-top: 14px;
}

/* Tab already labels the content — hide redundant section header inside panels */
.tab-panel .section-header {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

/* ── Bloomberg section header: bar + label ───────────────── */

.section-header {
  margin-bottom: 16px;
}

.section-header-bar {
  width: 40px;
  height: 3px;
  background: var(--rule-strong);
  margin-bottom: 8px;
}

.section-header-label {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-primary);
}

/* ── District profile: name / areas / lede ───────────────── */

/* Same size as the map label on the left — 20px bold */
.district-name {
  margin-bottom: 2px;
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: -0.01em;
  color: var(--ink-primary);
  font-variant-numeric: tabular-nums;
}

/* Neighborhoods listed smaller below the district name */
.district-neighborhoods {
  margin-bottom: 8px;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1.4;
  color: var(--ink-secondary);
}

.district-lede {
  max-width: 52ch;
  margin-bottom: 6px;
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  line-height: 1.5;
  color: var(--ink-primary);
}

/* Bolded numbers in the lede */
.district-lede .fig {
  font-weight: var(--weight-bold);
}


/* ── Metric summary cards (population, foreign-born) ─────── */

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

.metric-card {
  background: transparent;
}

.metric-card-label {
  margin-bottom: 4px;
  color: var(--ink-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  letter-spacing: 0.01em;
}

[data-tooltip] {
  position: relative;
  cursor: default;
  text-decoration: underline dotted var(--rule-light);
  text-underline-offset: 2px;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 5px);
  left: 0;
  width: max-content;
  max-width: 200px;
  white-space: normal;
  background: var(--rule-strong);
  color: #ffffff;
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  letter-spacing: 0;
  line-height: 1.4;
  padding: 5px 7px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease;
  z-index: 10;
}

[data-tooltip]:hover::after {
  opacity: 1;
}

.metric-card-value {
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  line-height: 1.04;
  color: var(--ink-primary);
}

/* ── Chart wraps, captions, source lines ─────────────────── */

.chart-wrap {
  margin-top: 8px;
  padding: 12px 0 0;
  border-top: 1px solid var(--rule-light);
}

.chart-description {
  margin-bottom: 12px;
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  line-height: 1.5;
  color: var(--ink-secondary);
}

.chart-caption {
  max-width: 60ch;
  margin-top: 8px;
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: 1.5;
  color: var(--ink-tertiary);
}

.chart-source {
  display: block;
  margin-top: 4px;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-tertiary);
}

.chart-dot-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 8px;
}

.chart-dot-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-secondary);
  font-size: var(--text-sm);
}

.chart-dot-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 0;
  flex-shrink: 0;
}

.chart-dot-legend-swatch.current {
  background: var(--ink-primary);
}

.chart-dot-legend-swatch.zoning {
  border: 1.5px solid var(--ink-primary);
  background: var(--bg-page);
}

.pyramid-shell {
  width: 100%;
  max-width: 100%;
}

.legend-inline,
.swatch-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 8px;
}

.legend-inline-item,
.swatch-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-secondary);
  font-size: var(--text-sm);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 0;
  flex-shrink: 0;
}

/* ── Stat rows — terminal density ────────────────────────── */

.stat-list {
  display: flex;
  flex-direction: column;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--rule-light);
}

.stat-label {
  max-width: 22ch;
  color: var(--ink-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1.3;
}


.stat-value-group {
  text-align: right;
  flex-shrink: 0;
}

.stat-value {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  color: var(--ink-primary);
}


.comparison-text {
  display: block;
  margin-top: 2px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.comparison-good {
  color: var(--positive);
}

.comparison-bad {
  color: var(--negative);
}

.comparison-neutral {
  color: var(--ink-tertiary);
}

.value-note {
  display: block;
  margin-top: 2px;
  font-size: var(--text-xs);
  color: var(--ink-tertiary);
}

.headline-callout {
  margin-top: 10px;
  padding: 9px 0 0;
  border-top: 1px solid var(--rule-light);
  font-size: var(--text-base);
  color: var(--ink-secondary);
}

/* ── SON priorities ──────────────────────────────────────── */

.issue-block {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--rule-light);
}

.issue-header {
  margin-bottom: 8px;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-tertiary);
}

.issue-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.issue-item {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.issue-rank {
  color: var(--ink-tertiary);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}

.issue-text {
  color: var(--ink-secondary);
  font-size: var(--text-sm);
  line-height: 1.4;
}

/* ── Amenity cells — shared-border data grid ─────────────── */

.amenity-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  outline: 1px solid var(--rule-strong);
}

.amenity-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 14px 10px 12px;
  border-right: 1px solid var(--rule-strong);
  border-bottom: 1px solid var(--rule-strong);
  border-radius: 0;
  background: var(--bg-page);
  text-align: center;
}

/* Remove right border on last column item */
.amenity-tile:nth-child(3n) {
  border-right: none;
}

/* Remove bottom border on last row items */
.amenity-tile:nth-child(n+4) {
  border-bottom: none;
}

.amenity-tile:disabled {
  opacity: 1;
  cursor: default;
}

.tile-value {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--ink-primary);
}

.tile-label {
  color: var(--ink-tertiary);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.3;
  max-width: 14ch;
}

.tile-count {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  font-style: italic;
  color: var(--ink-tertiary);
}

/* ── Race / ethnicity stacked bar ────────────────────────── */

.race-track {
  width: 100%;
  height: 14px;
  display: flex;
  overflow: hidden;
  border: 1px solid var(--rule-light);
  background: var(--bg-subtle);
}

.race-segment {
  height: 100%;
}

/* ── Empty / error state ─────────────────────────────────── */

.empty-state {
  padding: 24px 0;
  color: var(--ink-secondary);
}

/* ── SVG map paths ───────────────────────────────────────── */

.map-path {
  cursor: pointer;
  transition: fill 180ms ease, stroke 150ms ease, stroke-width 150ms ease, opacity 150ms ease;
}

.district-hit-area {
  cursor: pointer;
  pointer-events: fill;
}

.district-hit-area:focus-visible,
.map-path:focus-visible {
  outline: none;
}

.map-path.is-muted {
  opacity: 0.35;
}

/* ── SVG chart text — newsroom hairline style ────────────── */

.axis-label,
.age-label,
.slope-label,
.endpoint-label {
  fill: var(--ink-tertiary);
  font-size: 8.5px;
}

.age-label {
  font-size: 7.5px;
}

.midline {
  stroke: var(--rule-light);
  stroke-dasharray: 3 3;
}

/* Citywide overlay: dashed ink-tertiary outline */
.city-outline {
  fill: none;
  stroke: var(--ink-tertiary);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0.85;
}

.pyramid-bar.male {
  opacity: 1;
}

.pyramid-bar.female {
  opacity: 0.42;
}

.slope-axis {
  stroke: var(--rule-light);
}

.slope-line {
  fill: none;
}

.slope-point {
  stroke: var(--bg-page);
  stroke-width: 1.5;
}

.dumbbell-grid {
  stroke: var(--rule-light);
  stroke-dasharray: 2 4;
}

.dumbbell-category {
  fill: var(--ink-secondary);
  font-size: 9.5px;
  font-weight: 500;
}

.dumbbell-line {
  fill: none;
  stroke-linecap: square;
}

.dumbbell-gap {
  font-size: 9px;
  font-weight: 700;
}

/* ── Bloomberg editorial footer ──────────────────────────── */

.page-footer {
  margin-top: 56px;
  padding-top: 20px;
  border-top: 2px solid var(--rule-strong);
}

.footer-section-label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-primary);
}

.footer-methodology,
.footer-sources {
  max-width: 68ch;
  margin-bottom: 20px;
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  line-height: 1.6;
  color: var(--ink-secondary);
}

.footer-byline {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-tertiary);
}

.footer-byline a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 1100px) {
  .page-shell {
    padding-inline: 28px;
  }

  .layout-grid {
    gap: 32px;
  }
}

@media (max-width: 900px) {
  .page-shell {
    padding: 20px 18px 40px;
  }

  .page-header {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .page-headline {
    font-size: 36px;
    max-width: none;
  }

  .layout-grid {
    grid-template-columns: 1fr;
    gap: 28px;
  }

  .map-column {
    position: static;
  }

  .detail-panel {
    max-height: 74vh;
  }

  .section-block + .section-block {
    margin-top: 32px;
    padding-top: 16px;
  }

  /* 2-column amenity grid — fix shared borders */
  .amenity-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Reset 3-col rules */
  .amenity-tile:nth-child(3n) {
    border-right: 1px solid var(--rule-strong);
  }

  .amenity-tile:nth-child(n+4) {
    border-bottom: 1px solid var(--rule-strong);
  }

  /* Apply 2-col rules */
  .amenity-tile:nth-child(2n) {
    border-right: none;
  }

  /* Last row in 2-col is items 5 and 6 */
  .amenity-tile:nth-child(n+5) {
    border-bottom: none;
  }
}

@media (max-width: 640px) {
  .page-headline {
    font-size: 28px;
  }

  .chip-row {
    gap: 6px 16px;
    padding-top: 16px;
  }

  .metric-grid {
    gap: 12px;
  }
}
