/* Keep the existing accordion colours, spacing and right-aligned menu affordance. */
#mapSidebar #keyLegend {
    background-image: url(../images/down-arrow-lines.svg), url(../images/key-settings-heading.svg) !important;
    background-position: right 8px center, 12px center !important;
    background-size: 27px, 26px;
}

#legendSection.key-settings-panel {
    padding: 10px;
    color: #252525;
    font: 14px/1.4 Arial, sans-serif;
}

#legendSection.key-settings-panel *,
#legendSection.key-settings-panel *::before,
#legendSection.key-settings-panel *::after { box-sizing: border-box; }

#legendSection #showMapKeyTitle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin: 0 0 10px;
    padding: 0 0 10px !important;
    border-bottom: 1px solid #ddd;
    font-weight: 600;
    cursor: pointer;
}

#legendSection #showMapKey {
    flex: 0 0 17px;
    width: 17px;
    height: 17px;
    margin: 0;
    accent-color: #5878b4;
}

#legendSection .key-layout-options {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

#legendSection .key-layout-options legend {
    margin: 0 0 6px;
    padding: 0;
    font-size: 14px;
}

#legendSection .key-layout-choices {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

#legendSection label.key-layout-choice {
    display: block;
    position: relative;
    min-width: 0;
    margin: 0;
    padding: 0;
    font-size: 13px;
    cursor: pointer;
}

/* Native radios retain arrow-key selection and tab focus. */
#legendSection .key-layout-choice input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
}

#legendSection .key-layout-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 108px;
    padding: 10px 4px 7px;
    border: 1px solid #aaa;
    border-radius: 4px;
    background: #fafafa;
}

#legendSection .key-layout-choice:hover .key-layout-card { background: #f0f4ed; border-color: #728664; }
#legendSection .key-layout-choice input:checked + .key-layout-card {
    background: #e5f3dc;
    border-color: #47812e;
    box-shadow: inset 0 0 0 1px #47812e;
}

#legendSection .key-layout-diagram { display: block; width: 100%; max-width: 82px; height: 66px; }
#legendSection .key-layout-tick { display: none; position: absolute; top: 5px; right: 5px; width: 13px; height: 13px; }
#legendSection .key-layout-choice input:checked + .key-layout-card .key-layout-tick { display: block; }

#legendSection #landscapeKeyRows {
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 10px 0 0;
}

#legendSection #landscapeKeyRows label { width: auto; min-width: 0; padding: 0; font-size: 13px !important; }
#legendSection #numberOfRows {
    flex: 0 0 48px;
    width: 48px;
    min-height: 30px;
    margin: 0;
    padding: 3px 5px;
    border: 1px solid #aaa;
    border-radius: 3px;
    background: #fff;
    color: #222;
    font: inherit;
}

#legendSection .key-settings-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #ddd;
}

#legendSection #resetKeyButton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: auto;
    min-width: 0;
    height: auto;
    min-height: 32px;
    margin: 0;
    padding: 5px 9px;
    border: 1px solid #999;
    border-radius: 4px;
    background: #f2f2f2;
    color: #252525;
    font: 13px/1.4 Arial, sans-serif;
}

#legendSection #resetKeyButton img { width: 19px; height: 19px; }
#legendSection #resetKeyButton:hover { background: #e8eee2; border-color: #66844e; }
#legendSection .key-settings-footer .iconLink { position: static; display: block; flex: 0 0 28px; width: 28px; height: 28px; padding: 3px; }

#legendSection .key-layout-choice input:focus-visible + .key-layout-card,
#legendSection #showMapKey:focus-visible,
#legendSection #numberOfRows:focus-visible,
#legendSection #resetKeyButton:focus-visible,
#legendSection .iconLink:focus-visible { outline: 2px solid #426ab0; outline-offset: 2px; }
