/* Shared navigation keeps only a border outside the opening page. */
body[data-atlas-view]:not([data-atlas-view="home"]) > header[hidden] {
  display: none !important;
}
body[data-atlas-view]:not([data-atlas-view="home"]) .page-section-nav {
  border-top: 3px solid #b39255 !important;
}
.map-secondary-actions[hidden] { display: none !important; }

.atlas-section-identity:not([hidden]) {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding-inline: clamp(10px, 2vw, 22px);
  border-bottom: 2px solid #b89354;
  background: #532838;
  color: #fff5e2;
  font: 14px/1.2 Georgia, serif;
}
.atlas-section-identity a { justify-self: start; color: inherit; }
.atlas-section-identity > div {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #f3d89f;
}
.atlas-section-title {
  justify-self: end;
  color: #f3d89f;
  text-align: right;
  line-height: 1.25;
}
.atlas-section-identity details { position: relative; }
.atlas-section-identity summary { cursor: pointer; padding-block: 8px; list-style: none; }
.atlas-section-identity summary::-webkit-details-marker { display: none; }
.atlas-section-identity details > span {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px;
  border: 1px solid #b89354;
  border-radius: 4px;
  background: #532838;
  color: #fff5e2;
  white-space: nowrap;
}
/* The same side panel shows either the layer list or its filter controls. */
body .map-task-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
body .map-task-tabs:has([data-map-panel="layers"][aria-selected="true"]) {
  margin-block: 5px !important;
}
body .map-task-tabs:has([data-map-panel="layers"][aria-selected="true"]) + .map-action-explanation {
  font: 12px/1.35 'Times New Roman', serif !important;
  margin: 0 0 5px !important;
  padding: 0 0 4px !important;
}
body :is(#atlas-navigation-panel, .fullscreen-options):has(
  .map-task-tabs [data-map-panel="layers"][aria-selected="true"]
) {
  bottom: auto !important;
  height: auto !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
}
body :is(#map-task-layers, #fs-layers-panel):not([hidden]) {
  flex: 0 0 auto;
  overflow: visible !important;
}
body :is(#atlas-navigation-panel, .fullscreen-options):has(.top-slavery-options[open]) > :is(
  .map-workspace-more, .study-tools, .map-reference-tools
) { display: none !important; }
body :is(#map-task-layers, #fs-layers-panel) > * { flex-shrink: 0; }
body :is(#map-task-layers, #fs-layers-panel) .map-task-introduction { margin: 0 !important; }
body :is(#map-task-layers, #fs-layers-panel) .map-task-introduction h3 {
  font: 700 14px/1.3 'Times New Roman', serif !important;
  margin: 0 0 4px !important;
}
body :is(#map-task-layers, #fs-layers-panel) > :is(.toggles, fieldset) {
  display: grid;
  gap: 2px;
  margin: 0 !important;
  padding: 0 !important;
}
body :is(#map-task-layers, #fs-layers-panel) > :is(.toggles, fieldset) > legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
body :is(#map-task-layers, #fs-layers-panel) label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 28px !important;
  margin: 0 !important;
  padding: 3px 6px !important;
  font: 14px/1.15 'Times New Roman', serif !important;
}
body :is(#map-task-layers, #fs-layers-panel) .catalog-help > summary {
  min-height: 24px !important;
  padding-block: 4px !important;
}
body :is(#map-task-layers, #fs-layers-panel) label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0 !important;
}
body :is(#map-task-layers, #fs-layers-panel) .caliphate-map-toggle {
  background: #f0e5e9 !important;
  border-color: #c8aeb9 !important;
  color: #613e4c !important;
}
body :is(#map-task-layers, #fs-layers-panel):has(.top-slavery-options[open]) > :not(.top-slavery-options),
body .top-slavery-options .research-layer,
.top-slavery-options[open] > summary span:first-child,
.top-slavery-options:not([open]) > summary span:last-child {
  display: none !important;
}
.top-slavery-options { margin-top: 3px; border-top: 1px solid #ddcdb8; }
.top-slavery-options[open] { margin-top: 0; border-top: 0; }
.top-slavery-options[open] > summary { list-style: none; }
.top-slavery-options[open] > summary::-webkit-details-marker { display: none; }
.top-slavery-options > summary {
  color: #673548;
  cursor: pointer;
  font: 700 13px/1.3 'Times New Roman', serif;
  padding-block: 6px;
}
body .top-slavery-options h3 {
  font: 700 15px/1.3 'Times New Roman', serif !important;
  margin: 2px 0 6px !important;
}
body .map-task-panel .top-slavery-options .research-controls {
  margin: 0 !important;
  padding: 7px !important;
}
body .map-task-panel .top-slavery-options .research-layer-settings :is(label, select, button) {
  font: 13px/1.3 'Times New Roman', serif !important;
}
body .map-task-panel .top-slavery-options select,
body .top-slavery-options .map-filter-summary button {
  min-height: 29px !important;
  padding: 4px 6px !important;
}
body .top-slavery-options .research-layer-settings :is(label, select, p) {
  margin-block: 2px !important;
}
body .top-slavery-options .research-layer-settings {
  margin-top: 0 !important;
  gap: 2px !important;
}
body .top-slavery-options .research-layer-settings .research-stats { display: none; }
body .top-slavery-options .map-filter-summary .map-filter-path {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
body .top-slavery-options .map-filter-summary {
  margin: 6px 0 4px;
  padding: 6px;
}
body .top-slavery-options .map-filter-summary :is(p, summary, button),
body .top-slavery-options :is(.map-count-details, .map-reading-help) > summary {
  font: 12px/1.3 'Times New Roman', serif !important;
  margin: 0 0 3px !important;
}
body .top-slavery-options :is(.map-count-details, .map-reading-help) {
  margin-top: 4px;
  padding-top: 3px;
}
body .top-slavery-options :is(.map-count-details, .map-reading-help) > summary {
  min-height: 0 !important;
  padding-block: 4px;
}
body .top-slavery-options .map-filter-summary > details > summary {
  min-height: 0 !important;
  padding-block: 4px;
}
body .map-toolbar :is(.top-slavery-layer, .map-slavery-filters-button) {
  border: 1px solid #9b6b7f !important;
  background: #f0e5e9 !important;
  color: #653146 !important;
}
body .map-toolbar .top-slavery-layer[aria-pressed="true"] {
  background: #743e50 !important;
  color: #fffaf4 !important;
}
body .map-toolbar .map-slavery-filters-button[hidden] { display: none !important; }
body .map-toolbar .map-actions .historic-map-button { display: none !important; }
body :is(#atlas-navigation-panel, .fullscreen-options) > .map-sidebar-slavery {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 9px;
  margin: 5px 0 3px !important;
  padding: 7px 9px !important;
  border: 1px solid #d6bdc5;
  border-left: 3px solid #743e50;
  border-radius: 6px;
  background: #f4e9ed;
  color: #5f2f43;
  cursor: pointer;
  font: 14px/1.2 'Times New Roman', serif;
}
.map-sidebar-slavery:has(input:checked) { background: #ead9e0 !important; }
.map-sidebar-slavery input {
  width: 16px;
  height: 16px;
  flex: none;
  margin: 0 !important;
  accent-color: #743e50;
}
.map-sidebar-slavery :is(strong, small) { display: block; }
.map-sidebar-slavery small { margin-top: 2px; font-size: 12px; }
body .mapwrap .map-toolbar .map-actions #expand-map,
body .mapwrap .mobile-fullscreen-controls > button {
  background: #af2329 !important;
  border-color: #af2329 !important;
  color: #fff !important;
}
body .mapwrap .map-toolbar .map-actions #expand-map:hover,
body .mapwrap .mobile-fullscreen-controls > button:hover {
  background: #8d1920 !important;
  border-color: #8d1920 !important;
}
.map-toolbar .map-geography-actions {
  display: flex;
  align-items: stretch;
  gap: 7px;
}
.map-toolbar .map-geography-actions .volga-tool-group {
  display: flex;
  align-items: stretch;
}
body .mapwrap .map-toolbar .map-geography-actions button {
  min-height: 40px;
  font: 600 12px/1.4 'Times New Roman', serif;
}
.map-reference-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.map-reference-tools button {
  border: 1px solid #ba9a59;
  border-radius: 5px;
  padding: 8px 10px;
  background: #f3e5c4;
  color: #674e24;
  font: 700 13px/1.3 'Times New Roman', serif;
  cursor: pointer;
}
.map-reference-figure { margin: 0; }
.map-reference-figure img,
.atlas-reference-dialog img.caliphate-map-plate {
  display: block;
  width: min(100%, 88dvh);
  aspect-ratio: 2236 / 1720;
  margin: auto;
  object-fit: cover;
  object-position: top;
}
.map-reference-figure figcaption { margin-block: 8px; font-size: 14px; }
body .mapwrap > #toggle-map-navigation {
  position: absolute;
  z-index: 875;
  top: calc(var(--workspace-toolbar-height, 76px) + 30px);
  left: 22px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid #c8aaa0;
  border-radius: 6px;
  background: #fffcf7;
  color: #693849;
  font: 700 24px/1 Arial, sans-serif;
  cursor: pointer;
}
body .mapwrap > #toggle-map-navigation:hover { background: #f1e2e6; }
body .mapwrap > #toggle-map-navigation:focus-visible {
  outline: 3px solid #915b3c;
  outline-offset: 2px;
}
body #atlas-navigation-panel > h2,
body .fullscreen-options .map-panel-heading h2 {
  min-height: 26px;
  padding-inline-start: 34px;
}
body .mapwrap :is(#collapse-map-panel, #show-map-panel),
body .mapwrap > #toggle-map-navigation[hidden],
body .mapwrap.mobile-map-fullscreen > #toggle-map-navigation {
  display: none !important;
}
.map-toolbar .map-quick-guide > summary {
  background: #f3dea7;
  border-color: #c09a54;
}
.map-legend-dock {
  position: absolute;
  z-index: 850;
  left: 14px;
  bottom: 7px;
  display: flex;
  align-items: end;
  gap: 7px;
  max-width: calc(100% - 85px);
  pointer-events: none;
}
.map-legend-dock > * { pointer-events: auto; }
body .mapwrap .map-legend-dock > :is(.legend, .active-map-layers) {
  position: static !important;
  inset: auto !important;
  transform: none !important;
  margin: 0 !important;
  width: auto !important;
  max-width: 100%;
}
.map-legend-dock > .legend { flex: 0 0 auto; }
.map-legend-dock .active-map-layers {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 90px;
  overflow-y: auto;
  padding: 5px;
  border: 1px solid #d7c3b0;
  border-radius: 6px;
  background: #fffaf3;
}
body .mapwrap .map-legend-dock :is(.active-layers-label, .layer-chip-heat),
body .mapwrap .map-legend-dock .active-map-layers:not(:has(.active-layer-chip:not(.layer-chip-heat))) {
  display: none !important;
}
body .mapwrap:fullscreen .map-toolbar {
  padding: 6px 14px !important;
  border-width: 0 0 1px !important;
  border-radius: 0 !important;
}
body .mapwrap:fullscreen .map-toolbar .map-heading h2 {
  font-size: clamp(18px, 1.55vw, 24px) !important;
  line-height: 1.15 !important;
}
body .mapwrap:fullscreen .map-toolbar .map-heading p { margin-block: 3px 0 !important; }

@media (min-width: 1100px) {
  body .mapwrap .map-toolbar .map-toolbar-main {
    display: grid !important;
    grid-template-columns: minmax(195px, 1fr) minmax(0, max-content);
    align-items: center;
  }
  body .mapwrap .map-toolbar .map-actions {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: flex-end;
  }
  body .mapwrap .map-toolbar .map-heading h2 { font-size: clamp(19px, 1.6vw, 29px); }
}

@media (max-width: 700px) {
  .atlas-section-identity:not([hidden]) { gap: 8px; font-size: 12px; }
  .atlas-section-identity > div { gap: 6px; }
  .atlas-section-identity details > span { left: auto; right: 0; transform: none; }
  body[data-atlas-view="map"] #atlas-navigation-panel:has(.map-task-tabs [data-map-panel="layers"][aria-selected="true"]),
  body .mapwrap:fullscreen .fullscreen-options:has(.map-task-tabs [data-map-panel="layers"][aria-selected="true"]) {
    max-height: min(55dvh, 390px) !important;
  }
  .map-secondary-actions-panel .map-geography-actions {
    flex-wrap: wrap;
    margin-bottom: 6px;
  }
}

@media (max-width: 700px) {
  .map-toolbar .map-toolbar-main { display: block !important; }
  .map-toolbar .map-heading h2 {
    font-size: 18px !important;
    line-height: 1.3 !important;
    margin: 0 0 7px !important;
  }
  .map-toolbar .map-heading p { display: none !important; }
  .map-toolbar .map-actions {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 5px !important;
    align-items: stretch !important;
  }
  .map-toolbar .map-actions > button,
  .map-secondary-actions > summary {
    min-height: 44px !important;
    padding: 8px !important;
    font: 600 13px/1.3 'Times New Roman', serif !important;
    white-space: normal !important;
  }
  .map-toolbar .map-actions > button { flex: 1 1 auto; }
  .map-secondary-actions { position: relative; flex: 0 0 auto; }
  .map-secondary-actions > summary {
    display: flex;
    align-items: center;
    cursor: pointer;
    border: 1px solid #cdb6a1;
    border-radius: 4px;
    background: #fffaf3;
    color: #743e50;
    list-style: none;
  }
  .map-secondary-actions > summary::-webkit-details-marker { display: none; }
  .map-secondary-actions > summary:focus-visible {
    outline: 3px solid #a77b26;
    outline-offset: 2px;
  }
  .map-secondary-actions-panel {
    position: absolute;
    top: calc(100% + 7px);
    right: 0;
    z-index: 1200;
    width: min(270px, calc(100vw - 32px));
    max-height: 50dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 9px;
    border: 1px solid #cdb6a1;
    border-radius: 7px;
    background: #fffaf3;
    box-shadow: 0 4px 16px #30282a33;
  }
  .map-secondary-actions-panel > :is(button, a, details) {
    display: block !important;
    width: 100% !important;
    margin: 0 0 6px !important;
  }
  .map-secondary-actions-panel :is(button, a, summary) {
    min-height: 44px !important;
    font-size: 14px !important;
  }
  body[data-atlas-view="map"] .layout > aside {
    left: 10px !important;
    right: 64px !important;
    width: auto !important;
    bottom: auto !important;
    max-height: min(38dvh, calc(100% - var(--workspace-nav-height, 56px) - var(--workspace-toolbar-height, 96px) - 80px)) !important;
    min-height: 0 !important;
    overscroll-behavior: contain;
    background: #fffaf3 !important;
  }
  .mapwrap:fullscreen .fullscreen-options {
    left: 10px !important;
    right: 64px !important;
    width: auto !important;
    bottom: auto !important;
    max-height: min(38dvh, calc(100dvh - var(--map-toolbar-height, 96px) - 80px)) !important;
    min-height: 0 !important;
    overscroll-behavior: contain;
    background: #fffaf3 !important;
  }
  body[data-atlas-view="map"] .mapwrap .leaflet-top.leaflet-right {
    right: 10px !important;
    z-index: 850;
  }
  body[data-atlas-view="map"] .mapwrap .leaflet-control-zoom a {
    width: 42px;
    height: 42px;
    line-height: 42px;
  }
}

@media (max-width: 700px) {
  .map-secondary-actions-panel[popover] {
    position: fixed;
    inset: auto;
    margin: 0;
  }
  #atlas-map-section:has(.map-secondary-actions[open] .map-secondary-actions-panel:not([popover])) {
    z-index: 900;
  }
}
