#map-workspace {
  --tool-ink: #153449;
  --tool-accent: #007d8b;
  --tool-tint: #e8f5f5;
  align-items: start;
  grid-template-areas: "map list";
}
#map-workspace.has-tool { grid-template-areas: "map tools" "list list"; }
#map-workspace > .map-panel { grid-area: map; }
.map-active-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 9px 16px; border-bottom: 1px solid #d6e5e9; background: #f5fafb;
}
.map-active-title { font-size: .79rem; font-weight: 700; color: #355665; margin-right: 4px; }
.map-state-action {
  display: inline-flex; gap: 6px; align-items: center; justify-content: center;
  min-height: 34px; padding: 5px 10px; max-width: 100%; text-align: left;
  border: 1px solid #bfd4da; border-radius: 6px; color: #235567; background: white;
  font-size: .8rem; font-weight: 650; line-height: 1.2;
}
.map-state-action span:first-child { font-size: 1rem; line-height: 1; }
.map-state-action:hover { border-color: #1d8190; background: #e9f5f5; }
.map-state-action:focus-visible { outline: 2px solid #0a7584; outline-offset: 2px; }
.cmp-pick-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; }
.cmp-panel .cmp-clear { margin: -.25rem 0 .65rem; }
#map-location-panel { grid-area: list; }
.map-tool-panel {
  grid-area: tools;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--tool-ink);
  overflow: hidden;
}
.map-toolbar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: absolute;
  z-index: 450;
  top: 16px;
  left: 16px;
  padding: 5px;
  background: #fff;
  border: 1px solid #d5e0e5;
  border-radius: 9px;
  box-shadow: 0 2px 12px #1634481c;
}
.map-tool-button {
  display: grid;
  place-items: center;
  position: relative;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: #fff;
  color: #355668;
}
.map-tool-button svg, .tool-heading-icon svg {
  width: 21px; height: 21px;
  fill: none; stroke: currentColor; stroke-width: 1.65;
  stroke-linecap: round; stroke-linejoin: round;
}
.map-tool-button:hover, .map-tool-button[aria-expanded=true] { color: var(--tool-accent); background: var(--tool-tint); }
.map-tool-button[aria-expanded=true]::before {
  content: ""; position: absolute; left: -5px; width: 3px; height: 21px;
  border-radius: 0 2px 2px 0; background: var(--tool-accent);
}
.map-tool-button.has-overlay::after {
  content: ""; position: absolute; right: 3px; top: 4px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--tool-accent);
}
.map-tool-button:focus-visible, .tool-content :focus-visible, .pair-button:focus-visible {
  outline: 2px solid #133c70; outline-offset: 2px;
}
.tool-short { display: none; }
.tool-tip {
  display: none; position: absolute; left: calc(100% + 10px); padding: 5px 9px;
  border-radius: 4px; background: #173448; color: white; font-size: .79rem;
  white-space: nowrap; pointer-events: none;
}
.map-tool-button:is(:hover,:focus-visible) .tool-tip { display: block; }
.tool-header {
  display: flex; align-items: center; gap: 11px; padding: 16px 18px;
  border-bottom: 1px solid var(--line); background: #fcfefe;
}
.tool-heading-icon {
  display: grid; place-items: center; width: 35px; height: 35px;
  flex: 0 0 auto; border-radius: 7px; color: var(--tool-accent); background: var(--tool-tint);
}
.tool-header h2 { font-size: 1.14rem; margin: 0; color: var(--tool-ink); }
.tool-header .close-button { margin-left: auto; flex: 0 0 auto; }
.tool-content { padding: 16px 18px 20px; overflow: auto; max-height: min(66vh,710px); overflow-wrap: anywhere; }
.tool-point-picker { display: grid; gap: 5px; margin-bottom: 16px; }
.tool-point-picker > span { font-size: .82rem; font-weight: 600; }
.tool-content select { width: 100%; max-width: 100%; }
.tool-source { padding: 12px; background: #f3f8fa; border-radius: 5px; font-size: .82rem; color: #435d6b; line-height: 1.55; }
.dataset-layer-choice { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.dataset-layer-choice > span:nth-child(2) { flex: 1; }
.dataset-layer-choice strong,.dataset-layer-choice small { display: block; }
.dataset-layer-choice strong { font-size: .93rem; }
.dataset-layer-choice small { margin-top: 3px; color: #526674; font-size: .79rem; }
.dataset-layer-icon { color: #337988; width: 23px; text-align: center; font-size: 1.15rem; }
.dataset-layer-choice input, #tool-layers .footfall-toggle input, #tool-layers .madrid-layer-choice input { accent-color: var(--tool-accent); }
#tool-layers .footfall-panel, #tool-layers .madrid-layers-panel { margin: 10px 0; padding: 0; border: 0; }
.map-tool-legend {
  position: absolute; z-index: 401; bottom: 30px; left: 12px;
  max-width: min(76%,540px); background: #fffffff5; border: 1px solid #d3e2e6;
  border-left: 3px solid var(--tool-accent); border-radius: 4px; padding: 6px 10px;
  box-shadow: 0 2px 8px #18394a14; pointer-events: none;
}
.map-tool-legend span { display: block; color: #214456; font-size: .77rem; line-height: 1.5; overflow-wrap: anywhere; }
.location-entry { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; border-bottom: 1px solid #edf0f5; }
.location-entry .location-row { border-bottom: 0; }
.pair-actions { display: inline-flex; gap: 5px; align-items: center; }
.location-entry > .pair-actions { padding-right: 12px; }
.pair-button {
  display: inline-grid; place-items: center; padding: 0; width: 27px; height: 28px;
  border: 1px solid #c9d8de; background: white; color: #375868; font-size: .75rem; font-weight: 700;
}
.pair-button.slot-a { border-radius: 50%; }
.pair-button.slot-b { border-radius: 4px; }
.pair-button:hover, .pair-button[aria-pressed=true] { border-color: #007580; color: #005e68; background: #e3f3f3; }
.pair-button.slot-b[aria-pressed=true] { border-color: #596395; color: #3e4577; background: #efeff8; }
.popup-button + .pair-actions { margin-left: 8px; }
.pair-map-icon { font: bold 13px/25px var(--font,Arial,sans-serif); text-align: center; }
.pair-map-icon span { display: block; width: 100%; height: 100%; color: white; }
.pair-map-icon.slot-a { background: #007e8a; border-radius: 50%; outline: 2px solid white; }
.pair-map-icon.slot-b span { background: #49527e; clip-path: polygon(50% 0,100% 50%,50% 100%,0 50%); }
.list-scenario-state,.scenario-marker-note { display: block; color: #3e616e; font-weight: 600; }
.scenario-key { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.key-candidate { background: #007d8b; }
.key-excluded { background: #f6f7fa; border: 1.5px dashed #67768a; }
.key-pending { background: #ffedbd; border: 2px solid #92670e; }
#detail-comparison-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 10px 0; color: #506574; font-size: .85rem; }
#map-workspace [hidden] { display: none !important; }
@media (max-width: 850px) {
  .map-active-controls { gap: 5px; padding: 7px 10px; }
  .map-state-action { min-height: 40px; }
  #map-workspace, #map-workspace.has-tool { grid-template-columns: minmax(0,1fr); grid-template-areas: "map" "tools" "list"; gap: 12px; }
  #map-workspace .map-wrapper { display: grid; grid-template-areas: "canvas" "toolbar"; grid-template-columns: minmax(0,1fr); }
  #map-workspace #map { grid-area: canvas; height: clamp(390px,63svh,580px); }
  #map-workspace .leaflet-bottom { bottom: var(--sheet-height, 0px); }
  .map-toolbar {
    grid-area: toolbar; position: static; flex-direction: row; justify-content: space-around; border: 0; border-radius: 0;
    border-top: 1px solid var(--line); padding: 5px 4px; gap: 2px; box-shadow: none;
  }
  .map-tool-button { display: flex; flex: 1; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; height: 48px; }
  .map-tool-button svg { width: 19px; height: 19px; }
  .tool-short { display: block; font-size: .69rem; }
  .map-tool-button[aria-expanded=true]::before { left: calc(50% - 13px); top: -4px; width: 26px; height: 3px; }
  .map-tool-button:is(:hover,:focus-visible) .tool-tip { display: none; }
  .map-tool-legend { bottom: auto; top: 8px; left: 8px; max-width: 78%; }
  .map-wrapper > .map-tool-panel { grid-area: canvas; align-self: end; z-index: 430; display: flex; flex-direction: column; max-height: 51%; border: 0; border-top: 3px solid #8cc4c8; box-shadow: 0 -3px 12px #16344816; border-radius: 14px 14px 0 0; }
  .tool-header { gap: 9px; padding: 10px 14px; }
  .tool-content { min-height: 0; padding: 12px 14px; }
  .tool-header h2 { font-size: 1.03rem; }
  .location-entry > .pair-actions { padding-right: 9px; }
}
