html,
body,
#app {
  height: 100%;
  margin: 0;
}

html {
  overflow: hidden;
}

body {
  font-family: Arial, Helvetica, sans-serif;
  color: #16202a;
  background: #eef2f5;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 14px;
  background: #ffffff;
  border-bottom: 4px solid #9ec451;
  box-shadow: 0 1px 5px rgba(21, 35, 48, 0.12);
  z-index: 4;
}

.site-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.site-brand img {
  width: 62px;
  height: 62px;
  object-fit: contain;
  flex: 0 0 auto;
}

.site-brand h1,
.update-dialog h2 {
  margin: 0;
  color: #2f4778;
  font-size: clamp(20px, 2vw, 28px);
  line-height: 1.05;
}

.site-brand p:not(.site-eyebrow) {
  max-width: 780px;
  margin: 4px 0 0;
  color: #485b6b;
  font-size: 13px;
  line-height: 1.35;
}

.site-eyebrow {
  margin: 0 0 3px;
  color: #5d7435;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.site-actions {
  display: flex;
  align-items: stretch;
  gap: 9px;
  flex: 0 0 auto;
}

.help-button,
.update-card {
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.help-button {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  color: #ffffff;
  background: #2f4778;
  border: 1px solid #2f4778;
}

.help-button:hover,
.help-button:focus-visible {
  background: #20365f;
}

.update-card {
  display: grid;
  gap: 1px;
  min-width: 150px;
  padding: 7px 11px;
  color: #263143;
  background: #f7faf5;
  border: 1px solid #b8cc8a;
  cursor: pointer;
  text-align: left;
}

.update-card span,
.update-card small {
  color: #5a6a45;
  font-size: 10px;
  font-weight: 700;
}

.update-card strong {
  color: #2f4778;
  font-size: 14px;
}

.update-card:hover,
.update-card:focus-visible {
  border-color: #6d9033;
  background: #f0f6e8;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 8px 12px;
  background: #ffffff;
  border-bottom: 1px solid #c7d2dc;
  box-shadow: 0 1px 4px rgba(21, 35, 48, 0.14);
  z-index: 3;
  flex-wrap: wrap;
  min-width: 0;
}

.toolbar__group,
.layer-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.control-help,
.layer-help {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: #ffffff;
  background: #2f4778;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  flex: 0 0 auto;
}

.control-help:hover,
.control-help:focus-visible,
.layer-help:hover,
.layer-help:focus-visible {
  background: #9ec451;
  color: #263143;
  outline: 2px solid #2f4778;
  outline-offset: 1px;
}

.toolbar label,
.layer-row label {
  font-size: 13px;
  font-weight: 700;
}

.toolbar select,
.toolbar button,
.layer-actions input {
  height: 34px;
  border: 1px solid #98a9b6;
  border-radius: 5px;
  background: #ffffff;
  color: #16202a;
  font-size: 14px;
}

.toolbar select {
  min-width: 220px;
  padding: 0 8px;
}

.toolbar button {
  padding: 0 12px;
  cursor: pointer;
}

.toolbar button:hover,
.toolbar select:hover,
.layer-actions input:hover {
  border-color: #315e7e;
}

.toolbar__group--check input {
  width: 18px;
  height: 18px;
}

.toolbar__group--range input {
  width: 130px;
}

#historicLayer {
  min-width: 150px;
}

.shell {
  display: grid;
  grid-template-columns: 370px 1fr;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(140px, 1fr) minmax(120px, 0.45fr);
  min-height: 0;
  overflow: hidden;
  background: #ffffff;
  border-right: 1px solid #c7d2dc;
  z-index: 2;
}

.summary {
  padding: 12px;
  border-bottom: 1px solid #e2e8ee;
}

.summary h1,
.details h2,
.group-title {
  margin: 0;
  font-size: 15px;
  line-height: 1.3;
}

.summary h2 {
  margin: 0;
  color: #2f4778;
  font-size: 15px;
  line-height: 1.3;
}

.summary dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 12px;
  margin: 10px 0 0;
  font-size: 13px;
}

.summary dt {
  color: #556575;
}

.summary dd {
  margin: 0;
  font-weight: 700;
}

.layer-actions {
  padding: 10px 12px;
  border-bottom: 1px solid #e2e8ee;
}

.layer-actions input {
  width: 100%;
  padding: 0 9px;
}

.layer-list,
.details {
  overflow: auto;
  min-height: 0;
}

.group {
  border-bottom: 1px solid #e9eef3;
}

.group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  background: #f6f8fa;
  color: #22313f;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.group-title::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid #526575;
}

.group[data-open="true"] .group-title::after {
  content: "";
  border-top: 0;
  border-bottom: 7px solid #526575;
}

.group-title:hover {
  background: #edf2f6;
}

.group-count {
  display: inline-block;
  min-width: 20px;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #e4ebf0;
  color: #4c5e6e;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.group-title:focus {
  outline: 2px solid #8aa8bd;
  outline-offset: -2px;
}

.group-body {
  display: none;
}

.group[data-open="true"] .group-body {
  display: block;
}

.layer-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid #edf2f6;
}

.layer-help {
  width: 20px;
  height: 20px;
  font-size: 12px;
}

.layer-row input {
  width: 17px;
  height: 17px;
}

.layer-row small {
  color: #5c6d7b;
  font-size: 12px;
}

.source-badge {
  display: inline-block;
  margin: 4px 5px 0 0;
  padding: 1px 6px;
  border-radius: 4px;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.45;
}

.source-cheshire { background: #315e7e; }
.source-ons { background: #2c7a62; }
.source-dft { background: #b45f1f; }
.source-ea { background: #1f7294; }
.source-natural { background: #4c7c2f; }
.source-heritage { background: #7b4e94; }
.source-tithe { background: #6f4a24; }
.source-ofcom { background: #8a5d20; }
.source-land { background: #9b3f5a; }
.source-bgs { background: #68733a; }
.source-gov { background: #555f6d; }
.source-other { background: #66727d; }

.count {
  min-width: 26px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #eef3f6;
  color: #334653;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.details {
  padding: 12px;
  border-top: 1px solid #c7d2dc;
  font-size: 13px;
}

.details p {
  margin: 8px 0 0;
}

.details-intro {
  color: #334653;
  line-height: 1.45;
}

.source-card {
  margin-top: 10px;
  padding: 9px 10px;
  border: 1px solid #d6e0e8;
  border-radius: 6px;
  background: #f7fafc;
}

.source-card p {
  margin: 4px 0 6px;
  color: #485b6b;
  line-height: 1.4;
}

.details table {
  width: 100%;
  margin-top: 10px;
  border-collapse: collapse;
  table-layout: fixed;
}

.details th,
.details td {
  padding: 5px 0;
  border-top: 1px solid #e3e9ee;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

.details th {
  width: 42%;
  color: #556575;
  font-weight: 700;
}

.nested-table {
  max-width: 100%;
  overflow: auto;
}

.nested-table table {
  min-width: 620px;
  table-layout: auto;
}

.nested-table th,
.nested-table td {
  padding: 4px 6px;
  font-size: 11px;
}

.json-value {
  max-height: 180px;
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px;
}

.details a {
  color: #0c5d88;
  font-weight: 700;
}

.map-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#status {
  position: absolute;
  right: 14px;
  bottom: 14px;
  max-width: min(480px, calc(100vw - 28px));
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #c3cfd8;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 2px 10px rgba(21, 35, 48, 0.16);
  z-index: 2;
}

.popup {
  position: absolute;
  transform: translate(-50%, calc(-100% - 10px));
  min-width: 130px;
  padding: 7px 9px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid #9bacb8;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(21, 35, 48, 0.22);
  font-size: 13px;
  pointer-events: none;
  white-space: nowrap;
}

.popup::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 12px;
  height: 12px;
  background: #ffffff;
  border-right: 1px solid #9bacb8;
  border-bottom: 1px solid #9bacb8;
  transform: translateX(-50%) rotate(45deg);
}

.update-dialog {
  width: min(720px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 28px));
  padding: 0;
  border: 0;
  border-radius: 12px;
  color: #263143;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(15, 29, 42, 0.34);
}

.update-dialog::backdrop {
  background: rgba(25, 38, 51, 0.58);
}

.update-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border-bottom: 4px solid #9ec451;
}

.update-dialog__head button {
  padding: 8px 11px;
  border: 1px solid #9babb8;
  border-radius: 6px;
  background: #ffffff;
  cursor: pointer;
}

.update-log-content {
  max-height: calc(100vh - 150px);
  padding: 4px 20px 20px;
  overflow: auto;
}

.update-entry {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 14px;
  padding: 15px 0;
  border-bottom: 1px solid #dfe6ec;
}

.update-entry time {
  color: #5d7435;
  font-weight: 800;
}

.update-entry h3 {
  margin: 0;
  color: #2f4778;
  font-size: 15px;
}

.update-entry ul {
  margin: 6px 0 0;
  padding-left: 18px;
  color: #485b6b;
  font-size: 13px;
  line-height: 1.45;
}

.ol-attribution {
  font-size: 11px;
}

@media (max-width: 920px) {
  .site-header {
    align-items: flex-start;
  }

  .site-brand img {
    width: 52px;
    height: 52px;
  }

  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(260px, 42vh) minmax(0, 1fr);
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid #c7d2dc;
  }
}

@media (max-width: 720px) {
  #app {
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .site-header {
    display: grid;
    gap: 8px;
    padding: 8px 10px;
  }

  .site-brand img {
    width: 46px;
    height: 46px;
  }

  .site-brand h1 {
    font-size: 19px;
  }

  .site-brand p:not(.site-eyebrow) {
    display: none;
  }

  .site-actions {
    width: 100%;
  }

  .help-button,
  .update-card {
    flex: 1 1 0;
    min-width: 0;
  }

  .help-button {
    justify-content: center;
  }

  .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: center;
    gap: 7px;
    padding: 8px 10px;
  }

  .toolbar__group {
    width: auto;
    min-width: 0;
    gap: 5px;
  }

  .toolbar__group:nth-of-type(1),
  .toolbar__group:nth-of-type(5) {
    grid-column: 1 / -1;
  }

  .toolbar__group:nth-of-type(1) select,
  .toolbar__group:nth-of-type(5) select,
  .toolbar button {
    width: 100%;
    min-width: 0;
  }

  .toolbar__group--check,
  .toolbar__group--range {
    width: auto;
  }

  .toolbar__group--range input {
    width: min(80px, 21vw);
  }

  .shell {
    grid-template-rows: minmax(250px, 42vh) minmax(150px, 1fr);
  }

  .map-wrap {
    grid-row: 1;
  }

  .sidebar {
    grid-row: 2;
    grid-template-rows: auto auto minmax(90px, 1fr) minmax(80px, .4fr);
  }

  .update-entry {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
