/* Native data-view controls stay available to existing handlers while a single
   category strip presents their relevant subset. No duplicate element IDs. */
body.category-legends-open :is(#leftSidebar, #leftSidebarMining, #leftSidebarPower, #leftSidebarUtility, #leftSidebarFire, #leftSidebarPolice, #leftSidebarHospital, #leftSidebarSchool, #leftSidebarTourism, #rightSidebarRoad) {
    display: none !important;
}
#categoryLegendSidebar {
    --category-legend-btn-width: calc(var(--btn-size-lg) * 1.25);
    position: fixed;
    /* 다른 좌측 사이드바(#leftSidebar 등)처럼 화면 세로 중앙 정렬 — 위에 붙이지 않는다 */
    top: 50%;
    transform: translateY(-50%);
    left: calc(10px * var(--ui-scale));
    z-index: 100;
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    align-content: flex-start;
    gap: calc(6px * var(--ui-scale));
    max-height: calc(100dvh - 280px * var(--ui-scale));
    max-width: calc(100vw - 20px * var(--ui-scale));
    overflow-y: auto;
    overflow-x: hidden;
}
#categoryLegendSidebar[hidden], body.hide-ui #categoryLegendSidebar {
    display: none !important;
}
#categoryLegendSidebar .sidebar-btn {
    flex-shrink: 0;
    /* 글자 줄 수만큼 버튼이 늘어난다 — 고정 높이에 굵은 두 줄 글자가 박스 밖으로 밀려나던 문제 */
    /* 한글 세 글자 단어(행복도·소음원)가 중간에서 끊기지 않을 만큼 넓힌다 */
    width: var(--category-legend-btn-width);
    height: auto;
    min-height: var(--btn-size-lg);
    padding: calc(4px * var(--ui-scale)) calc(2px * var(--ui-scale));
    background: linear-gradient(300deg, var(--lp-tile-facet) 0 30%, transparent 30.5%), linear-gradient(180deg, var(--lp-tile-hi), var(--lp-tile-lo));
    border-color: var(--lp-tile-line);
    border-radius: calc(6px * var(--ui-scale));
    box-shadow: inset 0 calc(-3px * var(--ui-scale)) 0 var(--lp-tile-lip);
}
#categoryLegendSidebar .sidebar-btn .label {
    color: var(--lp-text);
    font-weight: 700;
    line-height: 1.15;
    max-width: 100%;
    text-align: center;
    text-transform: none;
    letter-spacing: 0;
    word-break: keep-all;
    overflow-wrap: anywhere;
}
/* 세로 한 줄에 다 안 들어가면 city-category-legends.js layout()이 열 수를 정한다 — 스크롤 막대 없음 */
#categoryLegendSidebar.multi-col {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: repeat(var(--legend-rows, 8), auto);
    /* 열 수를 명시해야 고정 위치 상자의 폭이 모든 열을 포함한다(암묵 열은 첫 열 폭만 잡혀 범례 창이 둘째 열을 덮었다) */
    grid-template-columns: repeat(var(--legend-cols, 2), var(--category-legend-btn-width));
    max-height: none;
    overflow: visible;
}
/* 띠가 원래 버튼 줄보다 넓으면(넓힌 버튼·여러 열) 시계 위젯(left 70px)과 범례 창(left 60px)을 띠 오른쪽으로 민다 */
body.category-legends-open #timeHUD {
    left: max(calc(70px * var(--ui-scale)), calc(var(--category-legend-width, 0px) + 20px * var(--ui-scale))) !important;
}
body.category-legends-open #dataViewLegend {
    left: max(calc(60px * var(--ui-scale)), calc(var(--category-legend-width, 0px) + 20px * var(--ui-scale))) !important;
}
#categoryLegendSidebar .sidebar-btn.active {
    background: linear-gradient(180deg, var(--lp-yellow-hi), var(--lp-yellow-lo));
    border-color: #9a6a00;
}
#categoryLegendSidebar .sidebar-btn.active .label { color: #4a2b00; }
@media (max-width: 768px), (max-height: 500px) {
    #categoryLegendSidebar {
        /* 모바일 가로 줄은 상단 고정 유지 */
        top: calc(76px * var(--ui-scale));
        transform: none;
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        max-height: none;
        padding-bottom: calc(4px * var(--ui-scale));
    }
    #categoryLegendSidebar .sidebar-btn {
        width: calc(48px * var(--ui-scale));
        min-height: calc(44px * var(--ui-scale));
    }
    #categoryLegendSidebar .label { display: none; }
}
