/* Housing Affordability Atlas — styles.css
 * Mobile-first, calm, public-data aesthetic. No external dependencies.
 * Color palette: slate ink, teal accent, sequential affordability scale.
 */

/* ---- Design tokens ----------------------------------------------------- */
:root {
  --ink: #0f1b2d;
  --ink-2: #3a4a5f;
  --muted: #6b7a8d;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --bg: #f7f9fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --brand: #0f766e;
  --brand-dark: #0b5650;
  --brand-tint: #d7f0ec;
  --focus: #1d4ed8;

  /* Sequential affordability scale (s1 least affordable -> s5 most) */
  --s1: #b4451f;
  --s2: #de8a4f;
  --s3: #f2d27a;
  --s4: #95c98b;
  --s5: #2f8f6b;
  --na: #d4dbe3;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(15, 27, 45, .06), 0 1px 3px rgba(15, 27, 45, .08);
  --shadow: 0 6px 20px rgba(15, 27, 45, .08);
  --shadow-lg: 0 14px 40px rgba(15, 27, 45, .12);
  --maxw: 1140px;
  --pad: clamp(16px, 4vw, 28px);
  --ease: cubic-bezier(.4, 0, .2, 1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { line-height: 1.2; color: var(--ink); font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: clamp(1.7rem, 4.5vw, 2.6rem); margin: .2em 0 .4em; }
h2 { font-size: clamp(1.3rem, 3vw, 1.7rem); margin: 1.6em 0 .5em; }
h3 { font-size: 1.1rem; margin: 0 0 .35em; }

a { color: var(--brand-dark); text-underline-offset: 2px; }
a:hover { color: var(--brand); }
p { margin: 0 0 1em; }

.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding-inline: var(--pad); }
.narrow { max-width: 820px; }
.muted { color: var(--muted); font-weight: 500; font-size: .85em; }
.lede { font-size: 1.12rem; color: var(--ink-2); max-width: 70ch; }
.section { margin: 2.2rem 0; }
.textlink { font-weight: 600; }

/* ---- Accessibility ----------------------------------------------------- */
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

:where(a, button, select, input, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---- Header / nav ------------------------------------------------------ */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; min-height: 62px; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; color: var(--ink); text-decoration: none; font-size: 1.05rem; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, var(--s5), var(--brand), var(--s3));
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.4);
}
.primary-nav { display: flex; gap: 4px; align-items: center; }
.primary-nav a {
  color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: .94rem;
  padding: 8px 12px; border-radius: 8px; transition: background .15s var(--ease), color .15s var(--ease);
}
.primary-nav a:hover { background: var(--surface-2); color: var(--ink); }
.primary-nav a[aria-current="page"] { color: var(--brand-dark); background: var(--brand-tint); }
.nav-toggle { display: none; flex-direction: column; gap: 4px; background: none; border: 1px solid var(--line-2); border-radius: 8px; padding: 9px 10px; cursor: pointer; }
.nav-toggle span { width: 20px; height: 2px; background: var(--ink); border-radius: 2px; }

@media (max-width: 760px) {
  .nav-toggle { display: flex; }
  .primary-nav {
    position: absolute; top: 62px; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 2px;
    background: var(--surface); border-bottom: 1px solid var(--line);
    padding: 10px var(--pad); box-shadow: var(--shadow);
    display: none;
  }
  .primary-nav.is-open { display: flex; }
  .primary-nav a { padding: 11px 12px; }
}

/* ---- Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 600; font-size: .95rem; text-decoration: none; cursor: pointer;
  padding: 11px 18px; border-radius: 10px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  transition: transform .12s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease);
}
.btn:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand-dark); }
.btn-ghost:hover { background: var(--surface-2); }

/* ---- Hero -------------------------------------------------------------- */
.hero {
  background:
    radial-gradient(1200px 400px at 80% -10%, var(--brand-tint), transparent 60%),
    linear-gradient(180deg, #fbfdff, var(--bg));
  border-bottom: 1px solid var(--line);
}
.hero-inner { padding: clamp(2.4rem, 7vw, 4.6rem) 0 clamp(1.6rem, 4vw, 2.6rem); }
.hero h1 { max-width: 16ch; }
.hero .lede { margin-bottom: 1.4rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 1rem; }
.hero-flag {
  display: inline-block; font-size: .8rem; font-weight: 600; color: var(--brand-dark);
  background: var(--brand-tint); padding: 4px 10px; border-radius: 999px; margin: 0;
}

/* ---- Feature grid ------------------------------------------------------ */
.feature-grid { display: grid; gap: 14px; grid-template-columns: 1fr; margin-top: 1rem; }
.feature {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-sm); transition: transform .15s var(--ease), box-shadow .15s var(--ease), border-color .15s var(--ease);
}
.feature:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--brand-tint); }
.feature h3 { color: var(--brand-dark); }
.feature p { margin: 0; color: var(--ink-2); font-size: .95rem; }
@media (min-width: 620px) { .feature-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 960px) { .feature-grid { grid-template-columns: repeat(4, 1fr); } }

/* ---- Map controls ------------------------------------------------------ */
.map-controls {
  display: grid; gap: 14px; grid-template-columns: 1fr;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow-sm); margin: 1.4rem 0;
}
.control { display: flex; flex-direction: column; gap: 6px; }
.control label { font-weight: 600; font-size: .85rem; color: var(--ink-2); }
.control select, .control input {
  font: inherit; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 9px;
  background: var(--surface); color: var(--ink); width: 100%;
}
.control select:disabled { background: var(--surface-2); color: var(--muted); }
@media (min-width: 720px) { .map-controls { grid-template-columns: repeat(4, 1fr); } }

/* ---- Map layout -------------------------------------------------------- */
.map-area { display: grid; gap: 18px; grid-template-columns: 1fr; }
@media (min-width: 900px) {
  .map-area { grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); align-items: start; }
  .map-side { position: sticky; top: 78px; }
}
.map-figure {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow-sm); position: relative;
}
.map-canvas { position: relative; min-height: 240px; }
.us-map { width: 100%; height: auto; display: block; }
.us-map .state {
  fill: var(--na); stroke: #fff; stroke-width: 1; cursor: pointer;
  transition: fill .2s var(--ease), transform .15s var(--ease), filter .15s var(--ease);
  transform-box: fill-box; transform-origin: center;
}
.us-map .state[data-band="s1"] { fill: var(--s1); }
.us-map .state[data-band="s2"] { fill: var(--s2); }
.us-map .state[data-band="s3"] { fill: var(--s3); }
.us-map .state[data-band="s4"] { fill: var(--s4); }
.us-map .state[data-band="s5"] { fill: var(--s5); }
.us-map .state[data-band="na"] { fill: var(--na); }
.us-map .state:hover,
.us-map .state:focus-visible { filter: brightness(1.08); transform: scale(1.012); outline: none; }
.us-map .state.is-selected { stroke: var(--ink); stroke-width: 2; filter: brightness(1.05); }
.us-map.no-motion .state { transition: fill .2s var(--ease); }
.us-map.no-motion .state:hover,
.us-map.no-motion .state:focus-visible { transform: none; }

.map-empty { color: var(--muted); text-align: center; padding: 2.5rem 1rem; }

.map-tip {
  position: absolute; transform: translate(-50%, -110%);
  background: var(--ink); color: #fff; padding: 7px 10px; border-radius: 8px;
  font-size: .82rem; line-height: 1.35; pointer-events: none; white-space: nowrap;
  box-shadow: var(--shadow); z-index: 5;
}

/* ---- Legend ------------------------------------------------------------ */
.map-legend {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.legend-title { display: block; font-weight: 700; font-size: .9rem; margin-bottom: 8px; }
.legend-scale { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.legend-scale li { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--ink-2); }
.legend-swatch { width: 16px; height: 16px; border-radius: 4px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.06); }
.legend-swatch[data-band="s1"] { background: var(--s1); }
.legend-swatch[data-band="s2"] { background: var(--s2); }
.legend-swatch[data-band="s3"] { background: var(--s3); }
.legend-swatch[data-band="s4"] { background: var(--s4); }
.legend-swatch[data-band="s5"] { background: var(--s5); }
.legend-swatch[data-band="na"] { background: var(--na); }

/* ---- Detail panel ------------------------------------------------------ */
.map-panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-sm);
}
.panel-hint { color: var(--muted); margin: 0; font-size: .95rem; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.panel-head h3 { margin: 0; font-size: 1.25rem; }
.badge {
  font-size: .76rem; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink);
}
.badge[data-band="s1"] { background: var(--s1); color: #fff; }
.badge[data-band="s2"] { background: var(--s2); color: #3a2410; }
.badge[data-band="s3"] { background: var(--s3); color: #4a3c10; }
.badge[data-band="s4"] { background: var(--s4); color: #16361f; }
.badge[data-band="s5"] { background: var(--s5); color: #fff; }
.panel-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.panel-stats div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.panel-stats dt { font-size: .74rem; color: var(--muted); margin: 0 0 2px; }
.panel-stats dd { margin: 0; font-weight: 700; font-size: 1rem; }
.panel-note { font-size: .9rem; color: var(--ink-2); }
.panel-actions { display: flex; flex-direction: column; gap: 8px; }
.panel-actions .btn { width: 100%; text-align: center; }

/* ---- Stat cards (state/place pages) ------------------------------------ */
.stat-cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 2px;
}
.stat-k { font-size: .76rem; color: var(--muted); }
.stat-v { font-size: 1.35rem; font-weight: 800; letter-spacing: -.02em; }
.stat-note { font-size: .72rem; color: var(--muted); }

.callout-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .callout-grid { grid-template-columns: repeat(3, 1fr); } }
.callout { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); }
.callout h3 { color: var(--brand-dark); }
.callout p { margin: 0; font-size: .92rem; color: var(--ink-2); }

/* ---- Tables ------------------------------------------------------------ */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.data-table { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 520px; }
.table-caption { caption-side: bottom; text-align: left; padding: 10px 14px; color: var(--muted); font-size: .8rem; }
.data-table th, .data-table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.data-table thead th { background: var(--surface-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); position: sticky; top: 0; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table td a { font-weight: 600; text-decoration: none; }
.data-table td a:hover { text-decoration: underline; }
.score-pill { display: inline-block; min-width: 34px; text-align: center; font-weight: 700; font-size: .82rem; padding: 3px 8px; border-radius: 999px; background: var(--na); color: var(--ink); }
.score-pill[data-band="s1"] { background: var(--s1); color: #fff; }
.score-pill[data-band="s2"] { background: var(--s2); color: #3a2410; }
.score-pill[data-band="s3"] { background: var(--s3); color: #4a3c10; }
.score-pill[data-band="s4"] { background: var(--s4); color: #16361f; }
.score-pill[data-band="s5"] { background: var(--s5); color: #fff; }

/* ---- Pills / lists ----------------------------------------------------- */
.pill-links { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 0; }
.pill-links a, .pill-muted {
  display: inline-block; padding: 7px 14px; border-radius: 999px; text-decoration: none;
  font-weight: 600; font-size: .9rem; border: 1px solid var(--line-2); background: var(--surface); color: var(--brand-dark);
}
.pill-links a:hover { background: var(--brand-tint); border-color: var(--brand-tint); }
.pill-muted { color: var(--muted); background: var(--surface-2); }
.assume-list { padding-left: 1.1rem; color: var(--ink-2); }
.assume-list li { margin-bottom: .3em; }

/* ---- Breadcrumbs ------------------------------------------------------- */
.breadcrumbs { margin: 1.2rem 0 .4rem; font-size: .85rem; }
.breadcrumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0; color: var(--muted); }
.breadcrumbs li + li::before { content: "›"; margin-right: 6px; color: var(--line-2); }
.breadcrumbs a { color: var(--ink-2); text-decoration: none; }
.breadcrumbs a:hover { color: var(--brand); }

/* ---- FAQ --------------------------------------------------------------- */
.faq details {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 4px 16px; margin-bottom: 10px; box-shadow: var(--shadow-sm);
}
.faq summary { cursor: pointer; font-weight: 600; padding: 12px 0; list-style: none; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; float: right; color: var(--brand); font-weight: 700; }
.faq details[open] summary::after { content: "–"; }
.faq p { margin: 0 0 12px; color: var(--ink-2); }

/* ---- CTA + disclaimer -------------------------------------------------- */
.cta-atlas {
  background: linear-gradient(135deg, var(--brand-tint), #eafaf7);
  border: 1px solid #bfe6df; border-radius: var(--radius); padding: 22px; margin: 2.2rem 0;
}
.cta-atlas h2 { margin-top: 0; }
.cta-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.disclaimer {
  background: #fff8ee; border: 1px solid #f0dcc0; border-radius: var(--radius);
  padding: 18px 20px; margin: 2.2rem 0; font-size: .9rem; color: #5c4a2e;
}
.disclaimer h2 { margin-top: 0; font-size: 1.05rem; color: #7a5d2e; }
.disclaimer a { color: #8a5a1a; }

/* ---- Ad slots ---------------------------------------------------------- */
.ad-slot {
  display: block; margin: 1.8rem 0; text-align: center; position: relative;
  background: var(--surface-2); border: 1px dashed var(--line-2); border-radius: var(--radius);
  padding: 10px; overflow: hidden;
}
.ad-label { display: block; font-size: .66rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin-bottom: 6px; }
.ad-placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .8rem; background: repeating-linear-gradient(45deg, #fff, #fff 10px, #f3f6f9 10px, #f3f6f9 20px); border-radius: 8px; }
/* Reserve space to minimize layout shift (CLS) */
.ad-horizontal .ad-placeholder { min-height: 90px; }
.ad-incontent .ad-placeholder { min-height: 250px; }
.ad-sidebar .ad-placeholder { min-height: 250px; }
.ad-footer .ad-placeholder { min-height: 90px; }
@media (min-width: 728px) { .ad-horizontal .ad-placeholder, .ad-footer .ad-placeholder { min-height: 90px; } }

/* ---- Footer ------------------------------------------------------------ */
.site-footer { background: var(--ink); color: #cdd7e3; margin-top: 3rem; }
.foot-grid { display: grid; gap: 26px; grid-template-columns: 1fr 1fr; padding-top: 2.4rem; padding-bottom: 1.4rem; }
.foot-col h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: #8aa0b8; margin: 0 0 10px; }
.foot-col ul { list-style: none; margin: 0; padding: 0; }
.foot-col li { margin-bottom: 7px; }
.foot-col a { color: #cdd7e3; text-decoration: none; font-size: .92rem; }
.foot-col a:hover { color: #fff; text-decoration: underline; }
.foot-base { border-top: 1px solid #233246; padding-top: 1.2rem; padding-bottom: 2rem; }
.foot-atlas { font-size: .95rem; color: #e2e9f1; }
.foot-atlas a { color: #7fe0cf; font-weight: 600; }
.foot-legal { font-size: .78rem; color: #8aa0b8; margin: 0; }
@media (min-width: 700px) { .foot-grid { grid-template-columns: repeat(5, 1fr); } }

/* ---- Source attribution & data status ---------------------------------- */
.source-strip, .source-line {
  font-size: .8rem; color: var(--muted); margin: .6rem 0 0; line-height: 1.5;
}
.panel-prov { font-size: .76rem; color: var(--muted); margin: -2px 0 12px; }
.legend-pending { font-size: .82rem; color: var(--ink-2); margin: 8px 0 0; }
.control-wide { grid-column: span 1; }
@media (min-width: 720px) { .control-wide { grid-column: span 2; } }

.status-list { list-style: none; padding: 0; margin: .6rem 0 0; }
.status-list li { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; font-size: .92rem; }
.status-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block;
  background: var(--line-2); position: relative; top: 1px;
}
.status-dot[data-status="real"] { background: var(--s5); }
.status-dot[data-status="derived"] { background: var(--s4); }
.status-dot[data-status="illustrative"] { background: var(--s3); }
.status-dot[data-status="pending"] { background: var(--s2); }
.status-dot[data-status="external"] { background: var(--brand); }

.roadmap-note {
  background: #f0f7fb; border: 1px solid #cfe3ee; border-left: 4px solid var(--brand);
  border-radius: var(--radius); padding: 18px 20px;
}
.roadmap-note h2 { margin-top: 0; font-size: 1.1rem; }

.foot-atlas-src { font-size: .76rem; color: #8aa0b8; margin: 0 0 6px; }

.data-flag {
  background: #fff4e5; border: 1px solid #f0d9b5; border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: .85rem; color: #7a5d2e; margin: 0 0 1rem;
}

.map-controls optgroup { font-weight: 700; }

/* ---- Reduced motion ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  .btn:hover, .feature:hover { transform: none; }
}
