/* Theme + layout based on your aesthetic */

/* =========================
   Design Tokens (Theme)
   ========================= */
:root {
  --brand-900: #0b3c5d;
  --brand-700: #155b8a;
  --brand: #1d65a6;
  --brand-600: #165a96;

  --ink-900: #0f172a;
  --ink: #1f2a37;
  --muted: #5b6b7b;

  --surface: #ffffff;
  --bg: #f6f9fc;
  --accent-bg: #eef5fc;

  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --success: #0f766e;
  --warning: #b45309;

  --space-1: 6px;
  --space-2: 12px;
  --space-3: 18px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 40px;

  --container-max: 1400px;
  --radius: 12px;
  --shadow-elev: 0 8px 34px rgba(2, 6, 23, 0.06);
}

/* =========================
   Global Resets
   ========================= */
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family:
    Inter,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial,
    "Noto Sans",
    "Apple Color Emoji",
    "Segoe UI Emoji",
    "Segoe UI Symbol",
    sans-serif;
  background: linear-gradient(135deg, #e9f5ff 0%, var(--bg) 100%);
  color: var(--ink);
  line-height: 1.6;
  padding: var(--space-5);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

p + p {
  margin-top: var(--space-4);
}

.stack {
  --stack-space: var(--space-4);
}
.stack > * + * {
  margin-block-start: var(--stack-space);
}
.stack--lg {
  --stack-space: var(--space-5);
}
.stack--xl {
  --stack-space: var(--space-6);
}
.stack--xxl {
  --stack-space: calc(var(--space-6) + 8px);
}

/* =========================
   Container + Layout
   ========================= */
.container {
  max-width: var(--container-max);
  margin: 0 auto;
  background: var(--surface);
  padding: var(--space-5);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-elev);
}

h1 {
  margin: 0;
  font-size: clamp(24px, 2.4vw, 32px);
  font-weight: 800;
  letter-spacing: 0.1px;
  color: var(--brand-900);
}

.tagline {
  color: var(--brand-700);
  font-weight: 600;
}

.description {
  color: var(--ink);
}

.page-footer {
  text-align: center;
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--muted);
}

.page-footer a {
  color: var(--brand-700);
  text-decoration: none;
  font-weight: 600;
}

.page-footer a:hover {
  text-decoration: underline;
}

/* Footer logo + text alignment */
.page-footer p {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
}
.page-footer .logo-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.page-footer .logo-link img {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  vertical-align: middle;
}

/* Footer remains visible to show Powered by logo */

.quick-instructions ol {
  margin-top: var(--space-2);
  padding-left: var(--space-5);
}

.section-description {
  margin-top: var(--space-2);
  color: var(--muted);
  font-size: 0.95rem;
}

.page-header > p {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

/* Keep grid utility for future aside if needed */
.page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 520px);
  gap: var(--space-6);
  align-items: start;
  margin-top: var(--space-5);
}
.sticky {
  position: sticky;
  top: 16px;
}

/* =========================
   Controls (Search)
   ========================= */
.controls {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  width: 100%;
}

/* Ensure new Places Autocomplete element fills the row and adopts theme */
#autocomplete {
  flex: 1;
  width: 100%;
  display: block;
}
#autocomplete:focus-within {
  outline: none;
  box-shadow: 0 0 0 3px rgba(29, 101, 166, 0.15);
}

.selections {
  margin-top: var(--space-4);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-4);
}
.selections fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  background: #fff;
}
.selections legend {
  font-weight: 600;
}
.selections label {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: var(--space-2);
}

/* Inline link-style buttons (e.g., More...) */
.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent, #2563eb);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}

.source-notes {
  margin-top: 6px;
}
.source-notes summary {
  cursor: pointer;
}

input[type="text"] {
  flex: 1;
  width: 100%;
  padding: 14px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 15px;
  color: var(--ink);
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}
input[type="text"]::placeholder {
  color: #98a2b3;
}
input[type="text"]:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(29, 101, 166, 0.15);
}

/* Google Places Autocomplete dropdown (legacy widget) */
.pac-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-elev);
  z-index: 10000;
}
.pac-item {
  padding: 10px 12px;
  color: var(--ink);
  font-size: 14px;
}
.pac-item:hover,
.pac-item-selected {
  background: var(--accent-bg);
}
.pac-matched {
  color: var(--brand-700);
}

button {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  padding: 12px 18px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.2px;
  transition:
    background-color 0.15s ease,
    transform 0.05s ease,
    box-shadow 0.15s ease;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.04),
    0 1px 3px rgba(0, 0, 0, 0.1);
}
button:hover {
  background: var(--brand-600);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
button:active {
  transform: translateY(1px);
}
button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* =========================
   Result Card + Components
   ========================= */
.result-box {
  margin-top: 0;
}

.card {
  background: linear-gradient(135deg, var(--accent-bg) 0%, #ffffff 100%);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: 12px;
  padding: var(--space-5);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
  flex-wrap: wrap;
}

.card__head-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.card__actions button {
  padding: 6px 12px;
  font-size: 0.9rem;
}

.card__title {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  color: var(--brand-900);
}

.updated {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.section-header {
  margin: var(--space-5) 0 var(--space-2) 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--brand-900);
  border-bottom: 2px solid var(--border);
  padding-bottom: 4px;
}

.section-block {
  background: #fff;
  padding: var(--space-4);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.section-block + .section-block {
  margin-top: var(--space-5);
}

.sub-section-header {
  margin: var(--space-3) 0 var(--space-1) 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--brand-900);
}

.kv {
  display: grid;
  grid-template-columns: minmax(140px, 45%) 1fr;
  gap: var(--space-2) var(--space-4);
  margin: var(--space-3) 0 var(--space-4) 0;
}
.kv .key {
  color: var(--muted);
  font-weight: 700;
  line-height: 1.5;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.kv .val {
  color: var(--ink);
  line-height: 1.6;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-6);
  margin-top: var(--space-5);
}
.comparison-grid.column-headers {
  margin-top: 0; /* no top margin for header row */
  margin-bottom: 0; /* remove space below header labels */
}
.section-block .comparison-grid.column-headers + .comparison-grid {
  margin-top: 0; /* remove gap between header labels and content boxes */
}
.comparison-grid .col {
  background: var(--accent-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  min-width: 0;
}

.column-headers .col {
  background: none;
  border: none;
  padding: 0;
  text-align: center;
  font-weight: 700;
}

.callout {
  margin: var(--space-3) 0 var(--space-4) 0;
  padding: 12px 14px;
  background: #fff;
  border: 1px dashed var(--border);
  border-left: 4px solid var(--warning);
  border-radius: 10px;
  font-weight: 400;
  color: var(--ink-900);
}

.dac-stats {
  margin: var(--space-2) 0 0 1.2em;
  padding: 0;
  list-style: disc;
}

.dac-stats li {
  margin: 2px 0;
}

.dac-tracts {
  margin-top: var(--space-2);
}

.updated--footer {
  display: block;
  margin-top: var(--space-4);
  text-align: right;
  color: var(--muted);
  font-size: 13px;
}

.note {
  color: var(--muted);
  font-size: 13px;
  margin-top: var(--space-2);
}

.link-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.pill {
  display: inline-block;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  margin-right: 6px;
  font-size: 0.9rem;
}

.toggle-tracts {
  background: none;
  border: none;
  color: var(--brand);
  cursor: pointer;
  padding: 0;
  margin-left: 4px;
  font-size: 0.9rem;
  text-decoration: underline;
}

.map-image {
  max-width: 100%;
  height: auto;
  display: block;
  margin-top: var(--space-4);
  border-radius: var(--radius);
  box-shadow: var(--shadow-elev);
}


.ces-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.85rem;
}

/* Accessibility */
.visually-hidden {
  position: absolute !important;
  height: 1px;
  width: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  white-space: nowrap;
  clip-path: inset(50%);
}

/* Responsive */
@media (max-width: 980px) {
  .page-grid {
    grid-template-columns: 1fr;
  }
  .sticky {
    position: static;
    top: auto;
  }
  .kv {
    grid-template-columns: 1fr;
  }
  .card__header {
    flex-direction: column;
    align-items: flex-start;
  }
  .card__head-left {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }
  .comparison-grid {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 520px) {
  .link-row {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    padding: 0;
    background: #fff;
  }
  .controls {
    display: none;
  }
  .container {
    box-shadow: none;
    border: none;
  }
  .card__actions {
    display: none;
  }
}

/* Loading spinner overlay */
.spinner-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.2);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.spinner {
  position: relative;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  background: var(--surface);
  color: var(--brand-900);
}

.spinner::before {
  content: "";
  box-sizing: border-box;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 8px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
