/* ============================================================
   TheImlers Health Atlas — atlas.css
   ============================================================ */

:root {
  --ha-brand:       #1B2E4D;
  --ha-brand-dark:  #111E33;
  --ha-brand-mid:   #243D66;
  --ha-brand-light: #2E6BAD;
  --ha-brand-pale:  #E8EDF5;
  --ha-bg:          #F4F6FA;
  --ha-bg-card:     #FFFFFF;
  --ha-ink:         #1B2E4D;
  --ha-ink-2:       #3A4F6E;
  --ha-ink-3:       #7A8FA8;
  --ha-rule:        #D4DCE8;
  --ha-green:       #1A6B4A;
  --ha-amber:       #C4901A;
  --ha-good:        #1A6B4A;
  --ha-warn:        #C4901A;
  --ha-bad:         #C4501A;
  --ha-radius:      5px;
  --ha-map-width:   42%;
  --ha-map-collapsed: 36px;
  --ha-transition:  0.3s cubic-bezier(0.4,0,0.2,1);
}

.theimlers-ha-root {
  background: var(--ha-bg);
  color: var(--ha-ink);
  font-family: 'Open Sans', sans-serif;
  font-weight: 400;
  font-size: 15px;
  line-height: 1.6;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.theimlers-ha-root * { box-sizing: border-box; }

/* ── Loading ─────────────────────────────────────────────────── */
.ha-loading {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; min-height: 300px;
  gap: 1rem; color: var(--ha-ink-3); font-size: 13px;
}
.ha-loading-spinner {
  width: 32px; height: 32px;
  border: 2px solid var(--ha-rule);
  border-top-color: var(--ha-brand-light);
  border-radius: 50%;
  animation: ha-spin 0.8s linear infinite;
}
@keyframes ha-spin { to { transform: rotate(360deg); } }

/* ── Toolbar ─────────────────────────────────────────────────── */
.ha-toolbar {
  background: var(--ha-brand);
  color: #fff;
  padding: 0 1.5rem;
  display: flex; align-items: center; gap: 1.5rem;
  height: 52px; flex-shrink: 0; z-index: 10; position: relative;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.ha-search-wrap { flex: 1; max-width: 380px; position: relative; }
.ha-search-input {
  width: 100%;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: var(--ha-radius);
  color: #fff; padding: 7px 12px 7px 34px;
  font-size: 13px; font-family: 'Open Sans', sans-serif;
  outline: none; transition: border-color 0.2s, background 0.2s;
}
.ha-search-input::placeholder { color: rgba(255,255,255,0.35); }
.ha-search-input:focus { border-color: rgba(255,255,255,0.38); background: rgba(255,255,255,0.13); }
.ha-search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: rgba(255,255,255,0.38); pointer-events: none; font-size: 14px;
}

.ha-autocomplete {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--ha-bg-card); border: 1px solid var(--ha-rule);
  border-radius: var(--ha-radius); max-height: 280px; overflow-y: auto;
  z-index: 1000; box-shadow: 0 8px 28px rgba(27,46,77,0.14); display: none;
}
.ha-autocomplete.active { display: block; }
.ha-autocomplete-item {
  padding: 9px 14px; cursor: pointer; font-size: 13px;
  color: var(--ha-ink); border-bottom: 1px solid var(--ha-rule);
  display: flex; align-items: center; justify-content: space-between;
  font-family: 'Open Sans', sans-serif;
}
.ha-autocomplete-item:last-child { border-bottom: none; }
.ha-autocomplete-item:hover { background: var(--ha-brand-pale); }
.ha-autocomplete-item .ac-state {
  font-size: 10px; color: var(--ha-ink-3); background: var(--ha-bg);
  padding: 2px 7px; border-radius: 3px; letter-spacing: 0.04em;
}

.ha-toolbar-actions { display: flex; gap: 8px; margin-left: auto; }
.ha-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.75); border-radius: var(--ha-radius);
  padding: 5px 14px; font-size: 12px; font-family: 'Open Sans', sans-serif;
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.ha-btn:hover { background: rgba(255,255,255,0.1); color: #fff; border-color: rgba(255,255,255,0.3); }
.ha-btn.active { background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.38); color: #fff; }

/* ── Body layout ─────────────────────────────────────────────── */
.ha-body { display: flex; flex: 1; overflow: hidden; min-height: 0; }

/* ── Map panel — collapsible ─────────────────────────────────── */
.ha-map-panel {
  flex: 0 0 var(--ha-map-width);
  border-right: 1px solid var(--ha-rule);
  display: flex; flex-direction: column;
  overflow: hidden; background: var(--ha-bg);
  transition: flex-basis var(--ha-transition);
  position: relative;
}

/* Collapsed: show only a thin tab strip */
.ha-map-panel.is-collapsed {
  flex: 0 0 var(--ha-map-collapsed);
}
.ha-map-panel.is-collapsed .ha-map-inner { display: none; }

/* Maximized: full width */
.ha-map-panel.is-maximized {
  flex: 0 0 100%;
}
.ha-map-panel.is-maximized + .ha-profile-panel { display: none; }

/* ── Map toggle tab ──────────────────────────────────────────── */
.ha-map-tab {
  background: var(--ha-brand);
  color: rgba(255,255,255,0.85);
  display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start;
  width: var(--ha-map-collapsed);
  flex-shrink: 0;
  border-right: 1px solid rgba(255,255,255,0.08);
  padding: 10px 0;
  gap: 10px;
  cursor: pointer;
  position: absolute; left: 0; top: 0; bottom: 0;
  z-index: 5;
  transition: background 0.15s;
}
.ha-map-tab:hover { background: var(--ha-brand-mid); }

/* When NOT collapsed, tab sits inside, pushed against left edge */
.ha-map-panel:not(.is-collapsed) .ha-map-tab {
  position: relative; left: auto; top: auto; bottom: auto;
  flex-direction: row;
  width: 100%; height: 32px;
  padding: 0 12px;
  border-right: none;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
  gap: 8px;
}

.ha-map-tab-icon {
  font-size: 14px; line-height: 1; flex-shrink: 0;
  transition: transform var(--ha-transition);
}
/* collapsed: arrow points right (expand) */
.ha-map-panel.is-collapsed .ha-map-tab-icon { transform: rotate(0deg); }
/* normal: arrow points left (collapse) */
.ha-map-panel:not(.is-collapsed):not(.is-maximized) .ha-map-tab-icon { transform: rotate(180deg); }
/* maximized: arrow points right (collapse back) */
.ha-map-panel.is-maximized .ha-map-tab-icon { transform: rotate(180deg); }

.ha-map-tab-label {
  font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase;
  font-family: 'Open Sans', sans-serif; white-space: nowrap;
}
/* Vertical label when collapsed */
.ha-map-panel.is-collapsed .ha-map-tab-label {
  writing-mode: vertical-rl;
  text-orientation: mixed;
}

.ha-map-tab-max {
  background: none; border: none;
  color: rgba(255,255,255,0.55); font-size: 13px;
  cursor: pointer; padding: 0; line-height: 1;
  transition: color 0.15s; margin-left: auto;
  display: none;
}
.ha-map-panel:not(.is-collapsed) .ha-map-tab-max { display: block; }
.ha-map-tab-max:hover { color: #fff; }

/* ── Map inner content ───────────────────────────────────────── */
.ha-map-inner {
  display: flex; flex-direction: column; flex: 1; overflow: hidden;
  /* offset for the tab bar when in normal state */
}
.ha-map-panel.is-collapsed .ha-map-inner { display: none; }

.ha-map-header {
  padding: 8px 12px; border-bottom: 1px solid var(--ha-rule);
  font-size: 11px; color: var(--ha-ink-3);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0; font-family: 'Open Sans', sans-serif;
}
.ha-map-breadcrumb { display: flex; align-items: center; gap: 5px; }
.ha-map-breadcrumb span { cursor: pointer; transition: color 0.15s; font-size: 11px; }
.ha-map-breadcrumb span:hover { color: var(--ha-ink); }
.ha-map-breadcrumb .sep { color: var(--ha-rule); cursor: default; }
.ha-map-breadcrumb span.current { color: var(--ha-ink); font-weight: 600; cursor: default; }
.ha-map-zoom-hint { margin-left: auto; font-size: 10px; color: rgba(122,143,168,0.5); }

.ha-map-svg-wrap { flex: 1; overflow: hidden; position: relative; }
#ha-map-svg { width: 100%; height: 100%; display: block; }

.ha-map-region {
  fill: #C8D3E2; stroke: #fff; stroke-width: 0.5;
  cursor: pointer; transition: fill 0.12s;
}
.ha-map-region:hover { fill: #A8BBCE; }
.ha-map-region.selected { fill: #2E6BAD !important; stroke: #fff; stroke-width: 1.5; }

/* Blue-themed choropleth quintiles */
.ha-map-region.q0 { fill: #E8EDF5; }
.ha-map-region.q1 { fill: #ADBFD8; }
.ha-map-region.q2 { fill: #6F92B8; }
.ha-map-region.q3 { fill: #3A6494; }
.ha-map-region.q4 { fill: #1B2E4D; }

.ha-map-tooltip {
  position: absolute; background: var(--ha-brand); color: #fff;
  font-size: 12px; font-family: 'Open Sans', sans-serif;
  padding: 6px 11px; border-radius: var(--ha-radius);
  pointer-events: none; white-space: nowrap;
  opacity: 0; transition: opacity 0.1s; z-index: 100;
  box-shadow: 0 4px 14px rgba(27,46,77,0.25);
}
.ha-map-tooltip.visible { opacity: 1; }
.ha-map-tooltip strong { display: block; font-weight: 600; }
.ha-map-tooltip span { color: rgba(255,255,255,0.6); font-size: 11px; }

.ha-map-legend {
  padding: 7px 12px; border-top: 1px solid var(--ha-rule);
  display: flex; align-items: center; gap: 8px;
  font-size: 10px; color: var(--ha-ink-3); flex-shrink: 0;
  font-family: 'Open Sans', sans-serif;
}
.ha-legend-swatches { display: flex; gap: 2px; align-items: center; }
.ha-legend-swatch { width: 18px; height: 7px; border-radius: 1px; }
.ha-map-choropleth-select {
  margin-left: auto; background: transparent;
  border: 1px solid var(--ha-rule); border-radius: var(--ha-radius);
  font-size: 10px; font-family: 'Open Sans', sans-serif;
  color: var(--ha-ink-3); padding: 3px 6px; cursor: pointer;
}

/* ── Profile panel ───────────────────────────────────────────── */
.ha-profile-panel { flex: 1; overflow-y: auto; min-width: 0; }

.ha-empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; min-height: 400px;
  gap: 1rem; color: var(--ha-ink-3); text-align: center; padding: 2rem;
}
.ha-empty-icon { font-size: 3rem; opacity: 0.2; }
.ha-empty-state h3 {
  font-family: 'The Girl Next Door', cursive;
  font-weight: 400; font-size: 1.6rem; color: var(--ha-brand);
}
.ha-empty-state p { font-size: 13px; max-width: 280px; }

/* ── County profile header ───────────────────────────────────── */
.ha-profile-header {
  background: var(--ha-brand); color: #fff;
  padding: 1.75rem 2rem 1.5rem;
  position: relative; overflow: hidden;
}
.ha-profile-header::before {
  content: attr(data-state);
  font-family: 'The Girl Next Door', cursive;
  font-size: 16rem; line-height: 1;
  position: absolute; right: -0.5rem; top: -2rem;
  opacity: 0.05; pointer-events: none;
}
.ha-ph-eyebrow {
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  color: rgba(255,255,255,0.45); margin-bottom: 0.4rem;
  font-family: 'Open Sans', sans-serif;
}
.ha-ph-title {
  font-family: 'The Girl Next Door', cursive;
  font-size: 2.4rem; line-height: 1.05; font-weight: 400;
  margin-bottom: 0.2rem; color: #fff;
}
.ha-ph-subtitle { font-size: 13px; color: rgba(255,255,255,0.5); margin-bottom: 1.5rem; }

.ha-ph-kpis {
  display: grid; grid-template-columns: repeat(5,1fr);
  gap: 1px; background: rgba(255,255,255,0.07);
  border-radius: var(--ha-radius); overflow: hidden;
}
.ha-ph-kpi { background: rgba(255,255,255,0.04); padding: 0.85rem 1rem; }
.ha-ph-kpi-val {
  font-family: 'The Girl Next Door', cursive;
  font-size: 1.55rem; line-height: 1; display: block; color: #fff;
}
.ha-ph-kpi-lbl {
  font-size: 9px; letter-spacing: 0.07em; text-transform: uppercase;
  color: rgba(255,255,255,0.45); margin-top: 3px; display: block;
  font-family: 'Open Sans', sans-serif;
}
.ha-ph-kpi-delta { font-size: 10px; margin-top: 2px; display: block; font-family: 'Open Sans', sans-serif; }
.ha-ph-kpi-delta.good { color: #7EDBA8; }
.ha-ph-kpi-delta.warn { color: #F2C94C; }
.ha-ph-kpi-delta.bad  { color: #EB7575; }

.ha-add-compare-btn {
  position: absolute; top: 1.25rem; right: 1.25rem;
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.8); border-radius: var(--ha-radius);
  padding: 5px 13px; font-size: 12px; font-family: 'Open Sans', sans-serif;
  cursor: pointer; transition: all 0.15s;
}
.ha-add-compare-btn:hover { background: rgba(255,255,255,0.16); color: #fff; }
.ha-add-compare-btn.added { background: var(--ha-good); border-color: var(--ha-good); color: #fff; }
.ha-add-compare-btn.full  { opacity: 0.4; cursor: default; }

/* ── Profile body sections ───────────────────────────────────── */
.ha-profile-body { padding: 1.5rem 2rem; }

.ha-section { margin-bottom: 2.5rem; }
.ha-section-hdr {
  display: flex; align-items: baseline; gap: 0.75rem;
  margin-bottom: 1rem; padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--ha-brand-pale);
}
.ha-section-num { font-size: 10px; color: var(--ha-ink-3); letter-spacing: 0.08em; }
.ha-section-title {
  font-family: 'The Girl Next Door', cursive;
  font-size: 1.3rem; font-weight: 400; color: var(--ha-brand);
}
.ha-section-desc { font-size: 12px; color: var(--ha-ink-3); margin-bottom: 1rem; max-width: 600px; }

.ha-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.ha-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

.ha-card {
  background: var(--ha-bg-card); border: 1px solid var(--ha-rule);
  border-radius: var(--ha-radius); padding: 1.25rem;
}
.ha-card-title {
  font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ha-ink-3); margin-bottom: 0.75rem;
  font-family: 'Open Sans', sans-serif; font-weight: 600;
}
.ha-chart-wrap { position: relative; width: 100%; }

.ha-legend-row {
  display: flex; align-items: center; gap: 1rem;
  font-size: 11px; color: var(--ha-ink-3); margin-bottom: 0.75rem;
  flex-wrap: wrap; font-family: 'Open Sans', sans-serif;
}
.ha-legend-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; margin-right: 4px;
}

.ha-stat-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px;
  background: var(--ha-rule); border: 1px solid var(--ha-rule);
  border-radius: var(--ha-radius); overflow: hidden;
}
.ha-stat-cell { background: var(--ha-bg-card); padding: 1rem 1.25rem; }
.ha-stat-num {
  font-family: 'The Girl Next Door', cursive;
  font-size: 1.7rem; line-height: 1; display: block; color: var(--ha-brand);
}
.ha-stat-num.good { color: var(--ha-good); }
.ha-stat-num.warn { color: var(--ha-warn); }
.ha-stat-num.bad  { color: var(--ha-bad); }
.ha-stat-lbl { font-size: 11px; color: var(--ha-ink-3); display: block; margin-top: 3px; line-height: 1.4; }
.ha-stat-ctx { font-size: 9px; color: var(--ha-ink-3); margin-top: 3px; display: block; letter-spacing: 0.03em; }

.ha-svi-bars { display: flex; flex-direction: column; gap: 0.6rem; }
.ha-svi-row  { display: flex; align-items: center; gap: 0.75rem; }
.ha-svi-lbl  { font-size: 11px; color: var(--ha-ink-2); width: 140px; flex-shrink: 0; }
.ha-svi-track { flex: 1; height: 5px; background: var(--ha-rule); border-radius: 3px; overflow: hidden; }
.ha-svi-fill  { height: 100%; border-radius: 3px; }
.ha-svi-val   { font-size: 10px; color: var(--ha-ink-3); width: 36px; text-align: right; }

/* ── Compare bar ─────────────────────────────────────────────── */
.ha-compare-bar {
  background: var(--ha-brand); border-top: 1px solid rgba(255,255,255,0.07);
  padding: 9px 1.5rem; display: flex; align-items: center; gap: 10px;
  flex-shrink: 0; flex-wrap: wrap;
}
.ha-compare-label {
  font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: rgba(255,255,255,0.45); white-space: nowrap; font-family: 'Open Sans', sans-serif;
}
.ha-compare-pills { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.ha-compare-pill {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.09); border: 1px solid rgba(255,255,255,0.14);
  border-radius: var(--ha-radius); padding: 4px 10px;
  font-size: 12px; color: rgba(255,255,255,0.9); font-family: 'Open Sans', sans-serif;
}
.ha-compare-pill-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.ha-compare-pill-remove {
  background: none; border: none; color: rgba(255,255,255,0.35);
  cursor: pointer; font-size: 14px; line-height: 1; padding: 0 0 0 2px; transition: color 0.15s;
}
.ha-compare-pill-remove:hover { color: #fff; }
.ha-compare-view-btn {
  background: var(--ha-brand-light); border: 1px solid rgba(255,255,255,0.15);
  color: #fff; border-radius: var(--ha-radius);
  padding: 6px 16px; font-size: 12px; font-family: 'Open Sans', sans-serif;
  cursor: pointer; margin-left: auto; white-space: nowrap; transition: background 0.15s;
}
.ha-compare-view-btn:hover { background: #3A6AAA; }

/* ── Compare view ────────────────────────────────────────────── */
.ha-compare-view { padding: 1.5rem 2rem; }
.ha-compare-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 2rem; }
.ha-compare-title {
  font-family: 'The Girl Next Door', cursive;
  font-size: 1.8rem; font-weight: 400; color: var(--ha-brand);
}
.ha-compare-back {
  background: none; border: 1px solid var(--ha-rule); border-radius: var(--ha-radius);
  padding: 5px 12px; font-size: 12px; font-family: 'Open Sans', sans-serif;
  color: var(--ha-ink-3); cursor: pointer; transition: all 0.15s;
}
.ha-compare-back:hover { border-color: var(--ha-brand); color: var(--ha-brand); }

.ha-compare-cols { display: grid; gap: 1rem; }
.ha-compare-cols.cols-2 { grid-template-columns: repeat(2,1fr); }
.ha-compare-cols.cols-3 { grid-template-columns: repeat(3,1fr); }

.ha-compare-county-hdr { border-radius: var(--ha-radius); padding: 1rem 1.25rem; color: #fff; }
.ha-compare-county-name { font-family: 'The Girl Next Door', cursive; font-size: 1.2rem; }
.ha-compare-county-sub  { font-size: 11px; opacity: 0.65; margin-top: 2px; font-family: 'Open Sans', sans-serif; }

.ha-compare-section { margin-bottom: 2rem; }
.ha-compare-section-title {
  font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ha-ink-3); margin-bottom: 0.75rem; padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--ha-brand-pale); font-family: 'Open Sans', sans-serif; font-weight: 600;
}
.ha-compare-metric-row { display: flex; align-items: center; border-bottom: 1px solid var(--ha-rule); }
.ha-compare-metric-row:last-child { border-bottom: none; }
.ha-compare-metric-lbl {
  flex: 0 0 180px; font-size: 12px; color: var(--ha-ink-3);
  padding: 8px 1rem 8px 0; font-family: 'Open Sans', sans-serif;
}
.ha-compare-metric-vals { flex: 1; display: grid; }
.ha-compare-metric-val {
  padding: 8px 12px; font-size: 13px; font-weight: 600;
  text-align: center; border-left: 1px solid var(--ha-rule);
}
.ha-compare-metric-val.best  { color: var(--ha-good); }
.ha-compare-metric-val.worst { color: var(--ha-bad); }

.ha-compare-chart-section { margin-bottom: 2rem; }
.ha-compare-chart-section .ha-compare-section-title { margin-bottom: 1rem; }
.ha-compare-chart-wrap {
  background: var(--ha-bg-card); border: 1px solid var(--ha-rule);
  border-radius: var(--ha-radius); padding: 1.25rem;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .ha-body { flex-direction: column; }
  .ha-map-panel { flex: 0 0 300px !important; width: 100%; border-right: none; border-bottom: 1px solid var(--ha-rule); }
  .ha-map-panel.is-collapsed { flex: 0 0 32px !important; }
  .ha-map-panel.is-maximized { flex: 0 0 100% !important; }
  .ha-map-panel:not(.is-collapsed) .ha-map-tab { writing-mode: initial; width: 100%; flex-direction: row; }
  .ha-map-panel.is-collapsed .ha-map-tab { writing-mode: initial; flex-direction: row; }
  .ha-ph-kpis { grid-template-columns: repeat(3,1fr); }
  .ha-grid-2, .ha-grid-3 { grid-template-columns: 1fr; }
  .ha-compare-cols { grid-template-columns: 1fr !important; }
  .ha-compare-metric-lbl { flex: 0 0 120px; }
  .ha-profile-body { padding: 1rem; }
}
@media (max-width: 600px) {
  .ha-ph-kpis { grid-template-columns: repeat(2,1fr); }
  .ha-toolbar { gap: 0.75rem; padding: 0 1rem; }
}
