/* Shared base styles for all ADU Pulse pages */
:root {
  --bg: #07100c;
  --bg-2: #0b1612;
  --surface: #0e1814;
  --surface-2: #131f1a;
  --hair: rgba(230, 241, 236, 0.08);
  --hair-strong: rgba(230, 241, 236, 0.14);
  --fg: #e6f1ec;
  --fg-soft: #c4d2cd;
  --fg-muted: #7f8c87;
  --fg-dim: #56635e;
  --emerald: #34d399;
  --emerald-2: #10b981;
  --emerald-soft: rgba(52, 211, 153, 0.14);
  --emerald-hair: rgba(52, 211, 153, 0.28);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.10);
  --amber-hair: rgba(251, 191, 36, 0.28);
  --rose: #fb7185;
  --rose-soft: rgba(251, 113, 133, 0.10);
  --rose-hair: rgba(251, 113, 133, 0.28);

  --bg-gradient-1: rgba(52,211,153,0.06);
  --bg-gradient-2: rgba(52,211,153,0.04);

  --font-display: 'Bricolage Grotesque', 'Manrope', system-ui, sans-serif;
  --font-body: 'Manrope', system-ui, sans-serif;
  --font-serif: 'Instrument Serif', Georgia, serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

/* Light theme — toggled via [data-theme="light"] on <html>. */
html[data-theme="light"] {
  --bg: #f7faf8;
  --bg-2: #eef3f0;
  --surface: #ffffff;
  --surface-2: #f4f7f5;
  --hair: rgba(12, 22, 18, 0.10);
  --hair-strong: rgba(12, 22, 18, 0.18);
  --fg: #0c1612;
  --fg-soft: #2c3a35;
  --fg-muted: #5e6b66;
  --fg-dim: #8a948f;
  --emerald: #047857;
  --emerald-2: #059669;
  --emerald-soft: rgba(4, 120, 87, 0.10);
  --emerald-hair: rgba(4, 120, 87, 0.24);
  --amber: #b45309;
  --amber-soft: rgba(180, 83, 9, 0.08);
  --amber-hair: rgba(180, 83, 9, 0.24);
  --rose: #be123c;
  --rose-soft: rgba(190, 18, 60, 0.06);
  --rose-hair: rgba(190, 18, 60, 0.22);
  --bg-gradient-1: rgba(4, 120, 87, 0.05);
  --bg-gradient-2: rgba(4, 120, 87, 0.03);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 240ms ease, color 240ms ease;
}
body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--bg-gradient-1), transparent 60%),
    radial-gradient(900px 600px at 90% 110%, var(--bg-gradient-2), transparent 60%),
    var(--bg);
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

.mono { font-family: var(--font-mono); font-feature-settings: "tnum","zero"; }
.label {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  color: var(--fg-muted);
}
::selection { background: var(--emerald-soft); color: var(--fg); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }
html[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(12, 22, 18, 0.12); }

/* Page max widths */
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 28px; }
.wrap-narrow { max-width: 960px; margin: 0 auto; padding: 0 28px; }

/* Status bars (used in compliance / infra cards) */
.bar3 { display: flex; height: 4px; border-radius: 2px; overflow: hidden; background: rgba(255,255,255,0.04); }
.bar3 > span { display: block; }

/* Card hover */
.card-hover { transition: all 200ms ease; }
.card-hover:hover { transform: translateY(-1px); border-color: var(--emerald-hair) !important; }

/* === Page transition: town profiles =================================== */
.town-enter {
  animation: townEnter 460ms cubic-bezier(.2,.7,.15,1) both;
}
@keyframes townEnter {
  0%   { opacity: 0; transform: translateY(14px); filter: blur(4px); }
  60%  { opacity: 1; filter: blur(0); }
  100% { opacity: 1; transform: translateY(0); }
}
.town-stagger > * {
  animation: townStagger 520ms cubic-bezier(.2,.7,.15,1) both;
}
.town-stagger > *:nth-child(1) { animation-delay: 40ms; }
.town-stagger > *:nth-child(2) { animation-delay: 110ms; }
.town-stagger > *:nth-child(3) { animation-delay: 180ms; }
.town-stagger > *:nth-child(4) { animation-delay: 250ms; }
.town-stagger > *:nth-child(5) { animation-delay: 320ms; }
.town-stagger > *:nth-child(6) { animation-delay: 390ms; }
@keyframes townStagger {
  0%   { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}
.town-exit {
  animation: townExit 220ms ease-in both;
}
@keyframes townExit {
  0%   { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-10px); filter: blur(3px); }
}

/* Smooth-in for any page section */
.fade-in { animation: fadeIn 480ms ease both; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* === Responsive shim — site is designed at 1440 but should degrade. === */
@media (max-width: 900px) {
  .wrap, .wrap-narrow { padding: 0 16px !important; }
}

/* === Print — clean light treatment for advocates & planners sharing pages */
@media print {
  @page { margin: 0.5in 0.55in; size: letter portrait; }
  html, body {
    background: white !important;
    color: #0c1612 !important;
  }
  body {
    background-image: none !important;
  }
  header[style*="sticky"], footer, .no-print { display: none !important; }
  a { color: #0c1612 !important; text-decoration: none !important; }
  .mono { color: #4a5450 !important; }
  .label { color: #4a5450 !important; }
  * {
    background-image: none !important;
    box-shadow: none !important;
    animation: none !important;
    transition: none !important;
  }
  section, div { break-inside: avoid; }
  h1, h2, h3, h4 { color: #0c1612 !important; break-after: avoid; }

  /* Force backgrounds to white-ish so type stays legible */
  [style*="rgba(14,24,20"], [style*="rgba(7,16,12"] {
    background: #ffffff !important;
    border-color: #d4ddd8 !important;
  }
  [style*="rgba(52,211,153,0.0"], [style*="rgba(52,211,153,0.1"] {
    background: #f0faf5 !important;
  }
}

/* ============================================================ *
 * RESPONSIVE / MOBILE LAYER
 * The prototype is authored at desktop width with inline-style grids.
 * `!important` in a stylesheet beats React inline styles (which never
 * carry !important), so we can collapse layouts here without rewriting
 * every component.
 * ============================================================ */

/* Guard against horizontal overflow site-wide */
html, body { max-width: 100%; overflow-x: hidden; }
img, svg, video { max-width: 100%; height: auto; }

/* ----- Tablet / small-desktop (≤ 1024px) ----- */
@media (max-width: 1024px) {
  /* Big asymmetric two-column layouts → single column */
  [style*="grid-template-columns: 1.5fr 1fr"],
  [style*="grid-template-columns: 1.4fr 1fr"],
  [style*="grid-template-columns: 1.2fr 1fr"],
  [style*="grid-template-columns: 1.15fr 1fr"],
  [style*="grid-template-columns: 1.05fr 1fr"],
  [style*="grid-template-columns: 1.6fr 1fr"],
  [style*="grid-template-columns: 380px 1fr"],
  [style*="grid-template-columns: 220px 1fr"],
  [style*="grid-template-columns: 1.4fr 1fr 1fr 1.2fr"] {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
  }
  /* Sticky sidebars shouldn't pin on tablet/phone */
  [style*="position: sticky"][style*="top: 88"],
  [style*="position: sticky"][style*="top: 100"] {
    position: static !important;
  }
}

/* ----- Phone (≤ 760px) ----- */
@media (max-width: 760px) {
  /* Card rows + multi-col grids collapse to a single column on phones */
  [style*="grid-template-columns: repeat(5, 1fr)"],
  [style*="grid-template-columns: repeat(4, 1fr)"],
  [style*="grid-template-columns: repeat(3, 1fr)"],
  [style*="grid-template-columns: 1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  /* Small count-tile strips stay 2-up so they aren't a tall stack */
  [style*="grid-template-columns: repeat(4, 1fr)"][style*="gap: 12"] {
    grid-template-columns: 1fr 1fr !important;
  }
  /* Filter / segmented control rows scroll sideways instead of overflowing */
  [style*="flex-wrap: wrap"] { flex-wrap: wrap !important; }

  /* Footer 4-col → 1 col */
  footer [style*="grid-template-columns"] { grid-template-columns: 1fr !important; gap: 28px !important; }

  /* Cost calculator: form + results stack */
  [style*="grid-template-columns: 380px 1fr"] { grid-template-columns: 1fr !important; }

  /* Section horizontal padding tightened */
  section[style*="padding: 48px 28px"],
  section[style*="padding: 32px 28px"],
  section[style*="padding: 24px 28px"],
  section[style*="padding: 36px 28px"] { padding-left: 16px !important; padding-right: 16px !important; }

  /* Giant hero headline scales down */
  h1[style*="font-size: 72px"] { font-size: 40px !important; line-height: 1.04 !important; }
  h1[style*="font-size: 64px"] { font-size: 36px !important; line-height: 1.05 !important; }
  h1[style*="font-size: 56px"] { font-size: 34px !important; }
  h1[style*="font-size: 48px"] { font-size: 30px !important; }
  h2[style*="font-size: 38px"], h2[style*="font-size: 36px"], h2[style*="font-size: 34px"] { font-size: 26px !important; }

  /* Nav: hide the center rail on phone (replaced by hamburger menu) */
  header nav[style*="border-radius: 999px"] { display: none !important; }
  /* Tighten header padding on mobile */
  header > div[style*="padding: 14px 28px"] { padding-left: 14px !important; padding-right: 14px !important; gap: 8px !important; }
  /* Logo MA badge can hide to save room */
  header a[href="ADU Pulse Homepage.html"] .mono { display: none !important; }

  /* Page-header meta box: stack under title */
  [style*="grid-template-columns: 1.4fr 1fr"][style*="gap: 56"] { grid-template-columns: 1fr !important; }

  /* Wide data tables (town directory, housing) → horizontal scroll
     instead of clipping. */
  [style*="grid-template-columns: 2fr 1.2fr 0.9fr 0.9fr 0.9fr 1.1fr 1.3fr 1.3fr"],
  [style*="grid-template-columns: 60px 1.6fr 1fr 0.8fr 0.8fr 0.8fr"],
  [style*="grid-template-columns: 46px 1.6fr 1fr 0.8fr 0.7fr 0.8fr 0.8fr 1fr 1fr"] {
    min-width: 560px;
  }

  /* "This week's pulse" rows: drop the inline sparkline, keep name + stats */
  [style*="grid-template-columns: 1.2fr 1fr 0.7fr 0.7fr"] {
    grid-template-columns: 1.4fr 0.8fr 0.8fr !important;
  }
  [style*="grid-template-columns: 1.2fr 1fr 0.7fr 0.7fr"] > svg { display: none !important; }

  /* The 2 & 3 col gap tables (State|Local|Gap) stack vertically */
  [style*="grid-template-columns: 1fr 1fr 1fr"][style*="gap: 1px"] { grid-template-columns: 1fr !important; }

  /* Generic 2-col detail grids → 1 col */
  [style*="grid-template-columns: 220px 1fr"] { grid-template-columns: 1fr !important; gap: 6px !important; }

  /* Filter / sort pill groups: let them scroll sideways instead of clipping */
  .filter-group { overflow-x: auto !important; -webkit-overflow-scrolling: touch; flex-shrink: 0; max-width: 100%; }
  .filter-group > div { flex-shrink: 0; }
  .filter-group .label { flex-shrink: 0; }

  /* Submit-tip "what to send" cards: 5-col → single column */
  .kinds-grid { grid-template-columns: 1fr !important; }

  /* Compare page: town picker stays 2-up (not a tall stack) */
  .compare-picker { grid-template-columns: 1fr 1fr !important; }

  /* Homepage housing teaser: 4 stats → 2x2 */
  .teaser-stats { grid-template-columns: 1fr 1fr !important; gap: 18px !important; }
  .teaser-stats > div { border-left: none !important; padding-left: 0 !important; }

  /* Reduce oversized section vertical padding */
  section[style*="padding: 64px"] { padding-top: 36px !important; padding-bottom: 44px !important; }
}

/* Horizontal-scroll wrapper helper for any element that opts in */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Print-only header (page identifier that prints) */
.print-only { display: none; }
@media print {
  .print-only {
    display: block !important;
    padding: 12px 0 18px;
    border-bottom: 1px solid #c9d2cd;
    margin-bottom: 24px;
  }
  /* Force grids to stack when narrow on paper */
  [data-print-stack] {
    display: block !important;
  }
  [data-print-stack] > * { margin-bottom: 18px !important; }

  /* Town profile print refinements */
  .town-enter, .town-stagger > *, .town-exit { animation: none !important; opacity: 1 !important; transform: none !important; }
  .print-page-break { break-before: page; }
}
