/* ===========================================================
   Greater Newburyport — embed-friendly market snapshot
   Light editorial palette. Designed for iframe embedding on
   Squarespace at any width from ~360px to ~1400px.
   =========================================================== */

:root {
  /* === Corporate brand === */
  --brand-navy: #1e335e;    /* primary */
  --brand-cyan: #c9ebfc;    /* light accent */

  /* Brand-derived variants */
  --navy-deep:  #14233f;    /* darker shadow of brand-navy */
  --navy-soft:  #3a4f7d;    /* lighter step toward cyan */
  --cyan-soft:  #dff3fd;    /* paler version for backgrounds */
  --cyan-tint:  rgba(201, 235, 252, 0.30);

  /* Text */
  --ink:        #1c2233;
  --ink-soft:   #44506b;
  --ink-mute:   #7f8aa2;

  /* Backgrounds */
  --paper:      #ffffff;
  --paper-2:    #f4f8fc;    /* very pale cyan-tinted cream */
  --rule:       rgba(30, 51, 94, 0.10);
  --rule-strong:rgba(30, 51, 94, 0.20);

  /* Legacy aliases (kept so existing rules keep working) */
  --navy:       var(--brand-navy);
  --gold:       var(--brand-navy);
  --gold-soft:  var(--navy-soft);

  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --sans:  'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --mono:  'JetBrains Mono', ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Embed-friendly: fill the iframe / parent container, no max-width.
   Squarespace controls outer width; we just need to flex with it. */
.app {
  width: 100%;
  margin: 0 auto;
  padding: clamp(1rem, 2.4vw, 2rem) clamp(1rem, 2.4vw, 2rem);
}

a { color: var(--navy); text-decoration: none; border-bottom: 1px solid rgba(29, 58, 95, 0.25); }
a:hover { border-bottom-color: var(--navy); }

/* ----- header ----- */
.head {
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1rem;
  margin-bottom: 1.4rem;
}
.head-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.6rem, 2.6vw, 2.4rem);
  color: var(--ink);
  margin: 0 0 0.3rem;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.head-light { color: var(--ink-mute); font-weight: 400; font-style: italic; }
.head-sub {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.86rem;
  font-family: var(--mono);
  letter-spacing: 0.03em;
}
.head-source { color: var(--brand-navy); font-weight: 600; }
.head::after {
  content: '';
  display: block;
  width: 60px;
  height: 3px;
  background: linear-gradient(90deg, var(--brand-navy), var(--brand-cyan));
  margin-top: 0.9rem;
  border-radius: 2px;
}

/* ----- metric bar ----- */
.metric-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0.3rem;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 999px;
  margin-bottom: 1.2rem;
  width: max-content;
  max-width: 100%;
}
.metric-bar button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  padding: 0.5rem 1.05rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.metric-bar button:hover { color: var(--ink); background: rgba(29, 58, 95, 0.06); }
.metric-bar button.active {
  background: var(--brand-navy);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(30, 51, 94, 0.30);
}
.metric-bar button:hover { color: var(--brand-navy); background: var(--cyan-tint); }
.metric-bar button.active:hover { color: #fff; background: var(--brand-navy); }

/* ----- Map Layers panel ----- */
.layers-panel {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.85rem 1rem 0.95rem;
  margin: -0.4rem 0 1.2rem;
}
.layers-title {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 0.65rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: baseline;
}
.layers-title small {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.76rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-mute);
}
.layers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.45rem;
}
.layer-toggle {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--ink);
  transition: all 0.15s ease;
  user-select: none;
}
.layer-toggle:hover { border-color: var(--brand-navy); }
.layer-toggle.active { border-color: var(--brand-navy); background: var(--cyan-soft); }
.layer-toggle input { display: none; }
.layer-swatch {
  width: 16px; height: 16px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.15);
  flex-shrink: 0;
}
.layer-name {
  flex: 1;
  line-height: 1.2;
}
.layer-name small {
  display: block;
  font-size: 0.66rem;
  color: var(--ink-mute);
  margin-top: 1px;
}
.layer-toggle.active .layer-name { font-weight: 600; }

/* ----- map ----- */
.map-wrap {
  position: relative;
  width: 100%;
  height: clamp(420px, 60vh, 620px);
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper-2);
  margin-bottom: 1.4rem;
}
.map { position: absolute; inset: 0; cursor: grab; }
.map:active { cursor: grabbing; }
.map canvas { display: block; }

.map-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

/* "Zoom in further" hint pill shown when parcels overlay is on
   but current zoom is below the MassGIS visibility threshold (z<14). */
.zoom-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--brand-navy);
  color: #fff;
  font-size: 0.78rem;
  font-family: var(--sans);
  font-weight: 500;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  box-shadow: 0 8px 22px rgba(30, 51, 94, 0.35);
  z-index: 10;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ----- legend ----- */
.legend {
  position: absolute;
  top: 14px; left: 14px;
  background: rgba(250, 247, 240, 0.95);
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  pointer-events: none;
  z-index: 5;
  backdrop-filter: blur(6px);
  max-width: 88%;
}
.legend-title {
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 0.45rem;
}
.legend-row { display: flex; gap: 0.4rem; }
.legend-stop {
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
  font-size: 0.7rem;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}
.legend-swatch { width: 28px; height: 8px; border-radius: 1px; }

/* ----- tooltip (deck.gl injects html into a styled element) ----- */
.tt {
  background: rgba(15, 22, 36, 0.97);
  color: #ffffff;
  border-radius: 6px;
  padding: 14px 16px;
  font-family: var(--sans);
  font-size: 12.5px;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 24px));
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  border: 1px solid rgba(201, 235, 252, 0.30);
}
.tt-name {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.25rem;
  color: var(--brand-cyan);
  margin-bottom: 0.6rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid rgba(201, 235, 252, 0.30);
  font-weight: 500;
}
/* Lighter tooltip for non-highlighted MA towns (just MLS stats) */
.tt-name-other { color: #fff; font-size: 1.1rem; }
.tt-other-sub {
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.65);
  margin: 0 0 0.4rem;
}
.tt-section {
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--brand-cyan);
  margin: 0.65rem 0 0.35rem;
  padding-top: 0.55rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.tt-section:first-of-type { padding-top: 0; border-top: none; margin-top: 0; }
.tt-row {
  display: flex;
  justify-content: space-between;
  gap: 1.2rem;
  padding: 3px 0;
  font-size: 0.82rem;
  align-items: baseline;
}
.tt-row span {
  color: #ffffff;
  opacity: 0.92;
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}
.tt-row b {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #ffffff;
  font-size: 0.88rem;
}

/* Row highlight for the currently-selected metric */
.tt-row.tt-active {
  background: rgba(201, 235, 252, 0.18);
  border-radius: 4px;
  padding: 4px 6px;
  margin: 1px -6px;
}
.tt-row.tt-active span { color: var(--brand-cyan); font-weight: 600; }
.tt-row.tt-active b   { color: var(--brand-cyan); font-size: 1.0rem; }

/* "Selected metric" headline block in tooltip */
.tt-selected {
  margin: 0.3rem 0 0.7rem;
  padding: 0.55rem 0.7rem;
  background: linear-gradient(135deg, rgba(30, 51, 94, 0.85), rgba(201, 235, 252, 0.18));
  border-left: 3px solid var(--brand-cyan);
  border-radius: 4px;
}
.tt-selected-label {
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brand-cyan);
  margin-bottom: 2px;
}
.tt-selected-value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.35rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.1;
}

/* ----- town cards beneath map ----- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.4rem;
}
.card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1rem 1.05rem;
  transition: all 0.25s ease;
  position: relative;
}
.card:hover {
  border-color: var(--brand-navy);
  box-shadow: 0 8px 24px rgba(30, 51, 94, 0.14);
  transform: translateY(-2px);
  background: linear-gradient(180deg, #fff 0%, var(--cyan-soft) 100%);
}
.card-town {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.18rem;
  color: var(--brand-navy);
  margin-bottom: 0.6rem;
  letter-spacing: -0.005em;
}
.card-stats {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.32rem 0.6rem;
  font-size: 0.84rem;
}
.card-stats dt {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.card-stats dd {
  margin: 0;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--ink);
  text-align: right;
}
.card-stats dd.accent {
  color: var(--brand-navy);
  background: var(--cyan-soft);
  padding: 0 0.4rem;
  border-radius: 3px;
  margin-left: 0.3rem;
}

/* Section labels inside a town card / tooltip */
.card-section {
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brand-navy);
  margin: 0.85rem 0 0.45rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--rule);
}
.card-section:first-of-type { padding-top: 0; border-top: none; margin-top: 0; }

/* Per-card link row to external GIS detail viewers */
.card-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.9rem;
}
.card-link {
  display: inline-block;
  padding: 0.4rem 0.7rem;
  background: var(--cyan-soft);
  color: var(--brand-navy);
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  border-radius: 4px;
  border-bottom: none;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.card-link-primary {
  background: var(--brand-navy);
  color: #fff;
}
.card-link:hover {
  background: var(--brand-navy);
  color: #fff;
  transform: translateX(2px);
}
.card-link-primary:hover {
  background: var(--navy-deep);
}

/* (tt-section now defined above with stronger contrast) */

/* ----- "Go deeper" external link row ----- */
.explore-row {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 0.9rem;
  align-items: stretch;
  margin-bottom: 1.6rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--rule);
  padding-top: 1.4rem;
}
.explore-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-mute);
  align-self: center;
  padding-right: 0.5rem;
}
.explore-link {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.85rem 1.1rem;
  background: linear-gradient(135deg, #fff, var(--cyan-soft));
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  transition: all 0.2s ease;
  text-decoration: none;
  border-bottom: 1px solid var(--rule-strong);
}
.explore-link:hover {
  border-color: var(--brand-navy);
  background: linear-gradient(135deg, var(--cyan-soft), #fff);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(30, 51, 94, 0.12);
}
.explore-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--brand-navy);
}
.explore-link:hover .explore-title { color: var(--navy-deep); }
.explore-sub {
  font-size: 0.78rem;
  color: var(--ink-soft);
}
@media (max-width: 700px) {
  .explore-row { grid-template-columns: 1fr; }
  .explore-label { padding: 0; }
}

/* ----- footer ----- */
.foot {
  border-top: 1px solid var(--rule);
  padding-top: 1.1rem;
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: var(--ink-mute);
}
.foot-credit {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.92rem;
  color: var(--ink-soft);
}
.foot-name { font-weight: 600; color: var(--navy); font-style: normal; }
.foot-meta {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  margin-top: 0.5rem;
}
.foot-disclaim {
  font-style: italic;
  font-family: var(--serif);
  font-size: 0.78rem;
  color: var(--ink-mute);
  margin-top: 0.5rem;
  max-width: 78ch;
  line-height: 1.5;
}

/* ----- prevent iOS double-tap zoom on UI buttons / pills ----- */
.metric-bar button,
.layer-toggle,
.card-link {
  touch-action: manipulation;
}

/* ----- responsive at narrow iframe / phone widths ----- */
@media (max-width: 720px) {
  .layers-grid { grid-template-columns: 1fr 1fr; }
  .map-wrap { height: clamp(360px, 56vh, 520px); }
  .metric-bar { width: 100%; justify-content: flex-start; overflow-x: auto; flex-wrap: nowrap; }
  .metric-bar::-webkit-scrollbar { display: none; }
  .legend { font-size: 0.66rem; padding: 0.5rem 0.65rem; top: 10px; left: 10px; max-width: 70%; }
  .legend-swatch { width: 22px; }
  .head-title { font-size: 1.55rem; }
  .head-sub { font-size: 0.78rem; flex-wrap: wrap; }
  .foot-meta { font-size: 0.64rem; word-break: break-word; }
}

@media (max-width: 520px) {
  .app { padding: 0.7rem; }
  .head-title { font-size: 1.4rem; line-height: 1.2; }
  .head-sub { font-size: 0.72rem; }
  .head::after { width: 44px; margin-top: 0.7rem; }
  .map-wrap { height: clamp(340px, 52vh, 460px); }
  .metric-bar { padding: 0.25rem; gap: 0.25rem; }
  .metric-bar button { padding: 0.42rem 0.75rem; font-size: 0.74rem; }
  .layers-panel { padding: 0.7rem 0.75rem 0.8rem; }
  .layers-grid { grid-template-columns: 1fr; gap: 0.35rem; }
  .layer-toggle { padding: 0.5rem 0.6rem; font-size: 0.78rem; }
  .layer-name small { display: inline; margin-left: 0.3rem; opacity: 0.7; }
  .cards { grid-template-columns: 1fr; gap: 0.7rem; }
  .card { padding: 0.85rem 0.9rem; }
  .card-stats { font-size: 0.8rem; }
  .legend { font-size: 0.62rem; top: 8px; left: 8px; max-width: calc(100% - 16px); }
  .legend-row { gap: 0.35rem; }
  .legend-stop { font-size: 0.62rem; }
  .legend-swatch { width: 18px; height: 7px; }
  .tt { font-size: 11.5px; padding: 11px 13px; min-width: 200px; }
  .tt-name { font-size: 1.1rem; }
  .zoom-hint { font-size: 0.72rem; padding: 0.45rem 0.8rem; white-space: normal; max-width: calc(100vw - 32px); }
  .foot-credit { font-size: 0.82rem; }
  .foot-disclaim { font-size: 0.7rem; line-height: 1.45; }
}
