:root {
  /* Public map palette — untouched by the admin redesign below. */
  --ink: #111;
  --paper: #fff;
  --rule: #111;
  --muted: #555;

  /* Admin palette. Accent is a "rubric red" — the color liturgical rubrics
     are traditionally printed in — used once, deliberately, for primary
     actions and status; everything else stays quiet neutrals. */
  --admin-bg: #f5f6f8;
  --admin-surface: #fff;
  --admin-ink: #1b1f27;
  --admin-muted: #667085;
  --admin-border: #e2e5ea;
  --admin-border-strong: #cdd2db;
  --admin-accent: #9c2b28;
  --admin-accent-hover: #7e221f;
  --admin-accent-soft: #f7e9e8;
  --admin-radius: 7px;
  --admin-shadow: 0 1px 2px rgba(20, 20, 25, 0.06);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', Times, serif;
}

body {
  font-size: 17px;
  line-height: 1.5;
}

a {
  color: var(--ink);
}

a:hover {
  color: var(--ink);
}

h1, h2, h3 {
  font-weight: 400;
  letter-spacing: 0.01em;
}

h1 {
  font-size: 1.6rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.4rem;
}

h2 {
  font-size: 1.2rem;
  margin-top: 1.5rem;
}

.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
}

/* ==========================================================================
   Admin — everything below is scoped to body.admin (set by the admin
   header/login partials) so the public map page above is unaffected: system
   sans instead of serif (no font download, and it reads as software rather
   than a document), a single red accent, and real corners/shadows instead
   of the Tufte hairline-only look.
   ========================================================================== */

body.admin {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--admin-bg);
  color: var(--admin-ink);
  font-size: 14.5px;
  line-height: 1.55;
}

body.admin a {
  color: var(--admin-ink);
}

body.admin a:hover {
  color: var(--admin-accent);
}

body.admin h1 {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  border-bottom: none;
  padding-bottom: 0;
}

body.admin h2 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 2rem;
}

/* Wider column for pages dominated by a table or side-by-side cards, where
   the 1040px default leaves addresses/URLs wrapping unnecessarily. */
body.admin.wide .container {
  max-width: 1400px;
}

/* Room for the fixed scrape-status-bar below so it never covers the last
   bit of page content. */
body.admin .container {
  padding-bottom: 3.5rem;
}

/* Always-visible thin strip reporting the automatic re-scrape job's state
   (see src/scrapeScheduler.js) — self-polls via htmx while a run is in
   progress, see footer.ejs. */
.scrape-status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 2rem;
  padding: 0 1.25rem;
  font-size: 0.78rem;
  color: var(--admin-muted);
  background: var(--admin-surface);
  border-top: 1px solid var(--admin-border);
}

.scrape-spinner {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border: 2px solid var(--admin-accent);
  border-right-color: transparent;
  border-radius: 50%;
  animation: admin-spin 0.6s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .scrape-spinner {
    animation: none;
  }
}

nav.admin-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem 0.4rem;
  background: var(--admin-surface);
  border-bottom: 1px solid var(--admin-border);
  box-shadow: var(--admin-shadow);
  padding: 0.6rem 1.25rem;
  margin-bottom: 1.5rem;
}

nav.admin-nav .brand {
  font-weight: 700;
  margin-right: 1rem;
  text-decoration: none;
  white-space: nowrap;
}

nav.admin-nav .brand:hover {
  color: var(--admin-ink);
}

nav.admin-nav .nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem;
  flex: 1 1 auto;
}

nav.admin-nav a {
  text-decoration: none;
  color: var(--admin-muted);
  padding: 0.4rem 0.65rem;
  border-radius: var(--admin-radius);
  font-weight: 500;
}

nav.admin-nav a:hover {
  color: var(--admin-ink);
  background: var(--admin-bg);
}

nav.admin-nav a.active {
  color: var(--admin-accent);
  background: var(--admin-accent-soft);
  font-weight: 600;
}

nav.admin-nav .view-map {
  margin-left: auto;
  color: var(--admin-muted);
}

.badge {
  display: inline-block;
  background: var(--admin-accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1;
  border-radius: 999px;
  padding: 0.2rem 0.4rem;
  margin-left: 0.15rem;
  vertical-align: 0.1em;
}

.logout-form {
  display: inline;
  margin: 0 0 0 0.5rem;
  border: none;
  padding: 0;
}

body.admin .logout-form button {
  font-weight: 500;
  background: none;
  color: var(--admin-muted);
  border: none;
  padding: 0;
  margin: 0;
  height: auto;
  cursor: pointer;
}

body.admin .logout-form button:hover {
  color: var(--admin-accent);
}

body.admin table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.92rem;
}

.list-filters {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0 0;
}

.list-filters input[type="search"] {
  flex: 1;
}

/* Without this, the select's width:100% (from the shared rule below) makes
   it claim the whole row as its flex-basis, leaving nothing for the search
   box above to grow into. */
body.admin .list-filters select {
  flex: 0 0 auto;
  width: auto;
  min-width: 190px;
}

.scroll-table {
  max-height: 60vh;
  overflow-y: auto;
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
}

.scroll-table table {
  margin-top: 0;
}

.scroll-table thead th {
  position: sticky;
  top: 0;
  background: var(--admin-surface);
}

.two-col {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 2rem;
}

.two-col .scroll-table {
  max-height: 60vh;
}

@media (min-width: 781px) {
  /* Locks the viewport so the mass centers list scrolls internally instead
     of growing the page — nav becomes a regular flex item since sticky
     positioning isn't needed when the body itself never scrolls. */
  body.admin.fit-viewport {
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  body.admin.fit-viewport nav.admin-nav {
    position: static;
    flex: 0 0 auto;
  }

  body.admin.fit-viewport .container {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.admin.fit-viewport .container h1 {
    flex: 0 0 auto;
  }

  body.admin.fit-viewport .two-col {
    flex: 1 1 auto;
    min-height: 0;
  }

  body.admin.fit-viewport .two-col > div:first-child {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
  }

  body.admin.fit-viewport .two-col .scroll-table {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
  }
}

@media (max-width: 780px) {
  .two-col {
    grid-template-columns: 1fr;
  }
}

body.admin th, body.admin td {
  text-align: left;
  padding: 0.55rem 0.75rem 0.55rem 0;
  border-bottom: 1px solid var(--admin-border);
  vertical-align: top;
}

body.admin th {
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--admin-muted);
  border-bottom: 1px solid var(--admin-border-strong);
}

body.admin tbody tr:hover {
  background: var(--admin-bg);
}

body.admin form {
  margin: 1rem 0;
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  padding: 1rem 1.1rem;
  background: var(--admin-surface);
}

/* #bulk-delete / #bulk-review hold no fields of their own — checkboxes
   elsewhere on the page target them via form="id" — so they'd otherwise
   render as an empty bordered card. */
body.admin form:empty {
  display: none;
}

body.admin label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--admin-muted);
  margin-top: 0.7rem;
  margin-bottom: 0.2rem;
}

/* Puts a form's fields side by side instead of stacked, for forms that
   repeat many times on one page (e.g. the geolocation queue) where
   stacked labels waste a lot of vertical space. */
.field-grid {
  display: grid;
  grid-template-columns: 2fr 2fr 1fr 1fr;
  gap: 0 0.75rem;
}

@media (max-width: 700px) {
  .field-grid {
    grid-template-columns: 1fr 1fr;
  }
}

body.admin input[type="text"],
body.admin input[type="url"],
body.admin input[type="email"],
body.admin input[type="password"],
body.admin input[type="search"],
body.admin select {
  width: 100%;
  height: 2.3rem;
  font: inherit;
  padding: 0 0.6rem;
  border: 1px solid var(--admin-border-strong);
  border-radius: 6px;
  background: var(--admin-surface);
  color: var(--admin-ink);
  margin-top: 0.15rem;
}

body.admin input:focus,
body.admin select:focus {
  outline: 2px solid var(--admin-accent);
  outline-offset: 1px;
  border-color: var(--admin-accent);
}

body.admin input[type="color"] {
  width: 4rem;
  height: 2.3rem;
  border: 1px solid var(--admin-border-strong);
  border-radius: 6px;
  padding: 0.2rem;
  margin-top: 0.15rem;
  background: var(--admin-surface);
}

body.admin button, body.admin input[type="submit"] {
  font: inherit;
  font-weight: 600;
  background: var(--admin-accent);
  color: #fff;
  border: 1px solid var(--admin-accent);
  border-radius: 6px;
  height: 2.3rem;
  padding: 0 1.1rem;
  margin-top: 1rem;
  cursor: pointer;
}

body.admin button:hover, body.admin input[type="submit"]:hover {
  background: var(--admin-accent-hover);
  border-color: var(--admin-accent-hover);
}

body.admin button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

body.admin button.secondary, body.admin .link-button {
  background: var(--admin-surface);
  color: var(--admin-ink);
  border: 1px solid var(--admin-border-strong);
}

body.admin button.secondary:hover {
  background: var(--admin-accent-soft);
  color: var(--admin-accent);
  border-color: var(--admin-accent);
}

/* htmx adds .htmx-request to a (boosted) form for the duration of its
   request — dim it, block clicks on it, and spin, so Scrape/Confirm/Geocode
   give feedback instead of going silent until the page swaps, and so the
   same action can't be double-fired while it's in flight. */
body.admin form.htmx-request {
  position: relative;
  opacity: 0.55;
  pointer-events: none;
}

body.admin form.htmx-request::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1.4rem;
  height: 1.4rem;
  margin: -0.7rem 0 0 -0.7rem;
  border: 3px solid var(--admin-accent);
  border-right-color: transparent;
  border-radius: 50%;
  animation: admin-spin 0.6s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  body.admin form.htmx-request::after {
    animation: none;
  }
}

body.admin .error, body.admin .notice {
  border: 1px solid var(--admin-border-strong);
  border-radius: 6px;
  padding: 0.65rem 0.9rem;
  margin: 1rem 0;
  background: var(--admin-bg);
}

body.admin .error {
  border-color: var(--admin-accent);
  background: var(--admin-accent-soft);
  color: var(--admin-accent-hover);
}

.swatch {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  border-radius: 3px;
  border: 1px solid var(--admin-border-strong);
  vertical-align: middle;
  margin-right: 0.35em;
}

.stat-row {
  display: flex;
  gap: 1rem;
  margin: 1.25rem 0;
  flex-wrap: wrap;
}

a.stat {
  flex: 1 1 160px;
  text-decoration: none;
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-top: 3px solid var(--admin-border-strong);
  border-radius: var(--admin-radius);
  box-shadow: var(--admin-shadow);
  padding: 1rem 1.1rem;
}

a.stat:hover {
  border-top-color: var(--admin-accent);
}

.stat-row .stat .n {
  font-size: 1.9rem;
  font-weight: 700;
  display: block;
}

.stat-row .stat .label {
  color: var(--admin-muted);
  font-size: 0.85rem;
}

.dash-actions {
  display: flex;
  gap: 0.75rem;
  margin: 0.75rem 0 1.5rem;
  flex-wrap: wrap;
}

.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  height: 2.3rem;
  padding: 0 1.1rem;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
}

.btn-primary {
  background: var(--admin-accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--admin-accent-hover);
  color: #fff;
}

.btn-secondary {
  background: var(--admin-surface);
  border: 1px solid var(--admin-border-strong);
  color: var(--admin-ink);
}

.btn-secondary:hover {
  border-color: var(--admin-accent);
  color: var(--admin-accent);
}

.pipeline {
  margin: 0.75rem 0 0;
  padding-left: 1.3rem;
}

.pipeline li {
  margin: 0.4rem 0;
}

body.admin .actions form {
  display: inline-block;
  border: none;
  padding: 0;
  margin: 0;
}

body.admin .actions button {
  margin-top: 0;
  height: 2rem;
  padding: 0 0.75rem;
  font-size: 0.85rem;
}

.muted {
  color: var(--admin-muted);
}

.card {
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  padding: 0.9rem 1.1rem;
  margin-bottom: 1rem;
  background: var(--admin-surface);
}

.candidate-card {
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  padding: 0.85rem 1.1rem;
  margin: 0.85rem 0;
  background: var(--admin-surface);
}

body.admin .candidate-card form {
  border: none;
  padding: 0;
  margin: 0;
}

.candidate-meta input[type="checkbox"] {
  vertical-align: middle;
  margin-right: 0.35em;
}

.candidate-card .candidate-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.dup-columns {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.dup-column {
  flex: 1;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  background: var(--admin-bg);
  border: 1px solid var(--admin-border);
  border-radius: 6px;
  padding: 0.8rem 0.9rem;
}

body.admin .dup-column form {
  margin: auto 0 0;
  border: none;
  padding: 0;
  background: none;
}

.dup-column form button,
.dismiss-form button {
  width: 100%;
  margin-top: 0.75rem;
}

.dismiss-form {
  margin-top: 0.75rem;
}

body.admin.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

body.admin.login-page .container {
  max-width: 340px;
  width: 100%;
}

/* --- Public map page --- */

#map {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

#map-banner {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--paper);
}

#map-title {
  position: fixed;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 0.3rem 0.9rem;
  font-variant: small-caps;
  letter-spacing: 0.03em;
  pointer-events: none;
}

#legend {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 1000;
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  max-width: 240px;
}

#legend summary {
  cursor: pointer;
  font-variant: small-caps;
  letter-spacing: 0.03em;
  padding: 0.15rem 0;
}

#legend[open] summary {
  margin-bottom: 0.3rem;
}

#legend-body {
  line-height: 1.7;
}

/* Render map tiles in grayscale to keep the black-and-white theme. */
.leaflet-tile-pane {
  filter: grayscale(1) contrast(1.05);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  border-radius: 0;
  border: 1px solid var(--ink);
  box-shadow: none;
}

.leaflet-popup-content {
  font-family: 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', Times, serif;
  font-size: 0.95rem;
  margin: 0.6rem 0.8rem;
}

@media (max-width: 600px) {
  #map-title {
    top: 0.5rem;
    padding: 0.25rem 0.6rem;
    font-size: 0.9rem;
  }

  #legend {
    top: auto;
    bottom: 2.5rem;
    right: 0.5rem;
    left: 0.5rem;
    max-width: none;
  }

  .leaflet-popup-content-wrapper {
    max-width: calc(100vw - 3rem);
  }

  /* Bring the zoom buttons up to a real touch target (~44px). */
  .leaflet-control-zoom a {
    width: 44px;
    height: 44px;
    line-height: 44px;
    font-size: 1.3rem;
  }
}

.leaflet-popup-content h3 {
  margin: 0 0 0.2rem;
  font-size: 1rem;
}

.leaflet-bar a {
  border-radius: 0 !important;
}

.pin-marker {
  position: relative;
  border: 1px solid #111;
  width: var(--pin-size, 10px);
  height: var(--pin-size, 10px);
  display: block;
  /* --glow-blur/--glow-opacity (map.js) stay 0 while zoomed out and ramp
     up near max zoom, so a cluster of pins doesn't fuzz together. */
  box-shadow: 0 0 var(--glow-blur, 0px) calc(var(--glow-blur, 0px) * 0.25) currentColor;
}

.pin-marker::after {
  content: '';
  position: absolute;
  inset: 0;
  background: inherit;
}

/* .glow-active (map.js) is only set once --glow-blur > 0, so the pulse
   isn't animating (invisibly) on every pin while zoomed out. */
:root.glow-active .pin-marker::after {
  animation: pin-pulse 1.8s ease-out infinite;
}

@keyframes pin-pulse {
  0% {
    transform: scale(1);
    opacity: calc(var(--glow-opacity, 0) * 0.6);
  }
  100% {
    transform: scale(3);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root.glow-active .pin-marker::after {
    animation: none;
  }
}

/* markerIcon's divIcon is bigger than the visible dot, purely to grow the
   tap target; center the dot inside that invisible box. */
.pin-marker-hitbox {
  display: flex;
  align-items: center;
  justify-content: center;
}
