/* legend buttons */
.hazard-legend-panel {
    position: relative;
    width: max-content;
    color: var(--text);
}

.hazard-legend-panel[open] {
    z-index: 30;
}

.hazard-legend-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: auto;
    min-width: 6.5rem;
    padding: 0.45rem 0.7rem;
    border: 0;
    border-radius: 6px;
    background: var(--surface);
    color: var(--primary-text);
    font: inherit;
    font-weight: 400;
    cursor: pointer;
    list-style: none;
    box-shadow: 0 0 0 1px var(--border-soft), 0 2px 8px var(--shadow);
}

.hazard-legend-panel.has-active-filter .hazard-legend-button {
    font-weight: 700;
}

.hazard-legend-button::-webkit-details-marker {
    display: none;
}

.hazard-legend-button::after {
    content: "▸";
    font-size: 0.9rem;
}

.hazard-legend-panel[open] .hazard-legend-button {
    background: var(--primary);
    color: var(--on-primary);
}

.hazard-legend-panel[open] .hazard-legend-button::after {
    content: "▾";
}

.hazard-legend-button:hover {
    background: var(--primary-soft);
}

.hazard-legend-panel[open] .hazard-legend-button:hover {
    background: var(--primary-hover);
}

.hazard-legend-body {
    position: absolute;
    top: 0;
    left: calc(100% + 8px);
    z-index: 20;
    width: min(340px, calc(100vw - 40px));
    max-height: min(60vh, 520px);
    overflow-y: auto;
    padding: 0.45rem 0.75rem 0.65rem;
    border-radius: 8px;
    background: var(--surface);
    font-size: 1rem;
    line-height: 1.3;
    box-shadow: 0 0 0 1px var(--border-soft), 0 4px 16px var(--shadow);
}

@media (max-width: 640px) {
    .hazard-legend-body {
        top: calc(100% + 6px);
        left: 0;
        width: min(300px, calc(100vw - 40px));
    }
}

.hazard-legend-panel ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.hazard-legend-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin: 0 -0.25rem;
    padding: 0.22rem 0.25rem;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
}

.hazard-legend-row:hover {
    background: var(--hover);
}

.hazard-legend-all {
    margin-bottom: 0.3rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border-soft);
    font-weight: 600;
}

.hazard-legend-row:not(.hazard-legend-all):has(input:not(:checked)) {
    opacity: 0.45;
    text-decoration: line-through;
}

.hazard-legend-row:has(input:focus-visible) {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
}

.hazard-legend-row input[type="checkbox"] {
    flex: 0 0 auto;
    margin: 0;
    accent-color: var(--focus);
}

.hazard-legend-swatch {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    border: 1px solid var(--swatch-border);
    border-radius: 50%;
}

.hazard-legend-icon {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
}

.hazard-legend-categories span {
    line-height: 1.2;
}
