:root {
  --ink: #302b26;
  --muted: #706b62;
  --paper: #fbf5ec;
  --paper-deep: #f2eadc;
  --sage: #7b8b6f;
  --sage-dark: #53644b;
  --terracotta: #b86f49;
  --terracotta-dark: #87492f;
  --line: #d9cebd;
  --white: #fffdf8;
  --shadow: 0 12px 36px rgb(68 53 38 / 12%);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: var(--terracotta-dark);
}

[hidden] {
  display: none !important;
}

.exchange-access {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.exchange-access-card {
  width: min(100%, 42rem);
  padding: clamp(1.4rem, 4vw, 2.5rem);
  border: 1px solid var(--line);
  border-left: 4px solid var(--terracotta);
  background: var(--white);
  box-shadow: var(--shadow);
}

.exchange-access-card p {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.2rem, 3vw, 1.65rem);
  line-height: 1.45;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.site-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem 2rem;
  padding: 0.9rem clamp(1rem, 4vw, 3.75rem) 0.85rem;
  border-bottom: 1px solid var(--line);
  background: rgb(251 245 236 / 94%);
}

.eyebrow,
.section-label {
  margin: 0 0 0.45rem;
  color: var(--sage-dark);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.25rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.45rem, 2.4vw, 1.9rem);
  font-weight: 500;
  letter-spacing: -0.02em;
}

.intro {
  max-width: 70ch;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.15rem;
  padding-bottom: 0.35rem;
}

nav a {
  color: var(--sage-dark);
  font-size: 0.88rem;
  font-weight: 750;
  text-decoration: none;
}

nav a:hover {
  text-decoration: underline;
}

main {
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: clamp(1rem, 2.5vw, 2rem) clamp(1rem, 4vw, 3.75rem);
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(19rem, 0.8fr);
  gap: clamp(1rem, 2vw, 1.75rem);
}

.directory-section,
.map-section,
.details-panel {
  min-width: 0;
}

.directory-section {
  grid-column: 1 / -1;
}

.directory-scroll {
  overflow-x: auto;
}

.directory-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.directory-table thead th {
  padding: 0 1rem 0.5rem 0;
  border-bottom: 2px solid var(--sage);
  color: var(--sage-dark);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-align: left;
  text-transform: uppercase;
}

.directory-table tbody th,
.directory-table tbody td {
  padding: 0.5rem 1rem 0.5rem 0;
  border-bottom: 1px solid var(--line);
  line-height: 1.4;
  text-align: left;
  vertical-align: top;
}

.directory-table tbody th {
  width: 36%;
  font-weight: 700;
}

.directory-table tbody td:nth-child(2) {
  width: 34%;
}

.directory-table tbody tr:last-child th,
.directory-table tbody tr:last-child td {
  border-bottom: 0;
}

.directory-table .pending {
  color: var(--muted);
}

.map-heading,
.details-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4.2rem;
}

h2 {
  margin-bottom: 0.7rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.35rem, 2vw, 1.8rem);
  font-weight: 500;
}

.coverage-summary {
  margin-bottom: 0.8rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
  text-align: right;
}

.sangha-controls {
  display: flex;
  justify-content: flex-end;
  margin: -0.2rem 0 0.75rem;
}

.sangha-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--sage-dark);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 750;
}

.sangha-toggle input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--sage-dark);
}

.sangha-toggle:has(input:disabled) {
  cursor: wait;
  opacity: 0.68;
}

.sangha-statistics {
  margin-bottom: 0.75rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--line);
  background: var(--paper-deep);
}

.sangha-statistics[hidden] {
  display: none;
}

.sangha-statistics-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.sangha-statistics h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  font-weight: 500;
}

.sangha-statistics-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.sangha-statistics-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.35rem 0.9rem;
  margin-top: 0.65rem;
}

.sangha-stat {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding-top: 0.3rem;
  border-top: 1px solid rgb(83 100 75 / 18%);
  color: var(--muted);
  font-size: 0.72rem;
}

.sangha-stat strong {
  color: var(--ink);
}

.sangha-stat.unassigned {
  color: var(--terracotta-dark);
  font-weight: 750;
}

#map {
  height: min(69vh, 720px);
  min-height: 480px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #dfe4dc;
  box-shadow: var(--shadow);
}

.leaflet-container {
  font: inherit;
}

.leaflet-control-zoom a {
  color: var(--ink);
}

.exchange-tooltip {
  max-width: 20rem;
  padding: 0.65rem 0.75rem;
  border: 0;
  border-radius: 2px;
  background: var(--white);
  box-shadow: 0 8px 26px rgb(46 39 31 / 20%);
  color: var(--ink);
  white-space: normal;
}

.exchange-tooltip::before {
  display: none;
}

.tooltip-place {
  margin-bottom: 0.35rem;
  color: var(--sage-dark);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.tooltip-region + .tooltip-region {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line);
}

.tooltip-region strong {
  display: block;
}

.tooltip-region span {
  display: block;
  margin-top: 0.12rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1.1rem;
  padding: 0.75rem 0 0.25rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.swatch {
  width: 1rem;
  height: 0.7rem;
  border: 1px solid;
}

.swatch.represented {
  border-color: var(--terracotta-dark);
  background: rgb(184 111 73 / 72%);
}

.swatch.overlap {
  border-color: #6d3d56;
  background: rgb(139 76 108 / 72%);
}

.swatch.open {
  border-color: #8d9188;
  background: rgb(173 180 169 / 22%);
}

.swatch.sangha {
  width: 0.7rem;
  height: 0.7rem;
  border-color: #fffdf8;
  border-radius: 50%;
  background: var(--sage-dark);
  box-shadow: 0 0 0 1px var(--sage-dark);
}

.map-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.details-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(min(69vh, 720px) + 7.75rem);
}

.active-details {
  flex: 0 0 auto;
  max-height: min(40vh, 22rem);
  min-height: 6.25rem;
  margin-bottom: 0.75rem;
  overflow: auto;
  padding: 0.9rem;
  border-left: 3px solid var(--terracotta);
  background: #f4e5d9;
}

.active-details p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.active-details h3 {
  margin: 0 0 0.4rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
  font-weight: 500;
}

.active-details .detail-region + .detail-region {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgb(135 73 47 / 20%);
}

.detail-meta {
  display: grid;
  grid-template-columns: 5.4rem 1fr;
  gap: 0.2rem 0.5rem;
  margin: 0;
  font-size: 0.82rem;
}

.detail-meta dt {
  color: var(--muted);
  font-weight: 650;
}

.detail-meta dd {
  margin: 0;
}

.boundary-pending {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0.14rem 0.35rem;
  background: #eee2ca;
  color: #735d34;
  font-size: 0.7rem;
  font-weight: 750;
}

.error-card {
  padding: 1rem;
  border: 1px solid #d5a89a;
  background: #f8e3dc;
  color: #733a2a;
}

footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-top: auto;
  padding: 0.8rem clamp(1rem, 4vw, 3.75rem);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.7rem;
}

@media (max-width: 900px) {
  .site-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 1rem;
  }

  main {
    grid-template-columns: 1fr;
  }

  #map {
    height: 58vh;
    min-height: 420px;
  }

  .details-panel {
    max-height: none;
  }

  .active-details {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 520px) {
  .site-header {
    padding-top: 1.2rem;
  }

  .map-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .coverage-summary {
    margin-top: -0.4rem;
    text-align: left;
  }

  .sangha-controls {
    justify-content: flex-start;
  }

  .sangha-statistics-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  #map {
    height: 56vh;
    min-height: 360px;
  }
}
