.legend {
    box-sizing: border-box;
    width: 100%;
    padding: 10px 12px;
    background: var(--panel-background);
    border-radius: 8px;
    box-shadow: var(--panel-shadow);
    font: 13px/1.4 system-ui, sans-serif;
}

.legend-title {
    margin: 0 0 8px;
    color: #444;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 3px 0;
    cursor: pointer;
    user-select: none;
}

.legend-group {
    margin: 2px 0;
    padding: 2px 0 4px;
}

.legend-group__parent .legend-visual {
    display: none;
}

/* grouped layers omit a normal parent icon but still expose load failures */
.legend-group__parent .legend-visual--loading,
.legend-group__parent .legend-visual--error {
    display: grid;
}

.legend-group__children {
    padding-left: 19px;
}

.legend-group__child {
    font-size: 12px;
}

.legend-group__key {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 1px 0 2px 46px;
    color: #666;
    font-size: 10px;
    line-height: 1.25;
}

.legend-group__key-item {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.legend-group__key .legend-camera-symbol {
    --legend-marker-color: #777;
}

.legend-camera-symbols,
.legend-camera-group-symbol {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    width: 17px;
    height: 17px;
}

.legend-camera-symbol {
    display: block;
    box-sizing: border-box;
    width: 7px;
    height: 7px;
    background: var(--legend-marker-color);
    border: 1px solid color-mix(in srgb, var(--legend-marker-color) 45%, #000);
}

.legend-camera-symbol--triangle {
    width: 0;
    height: 0;
    background: transparent;
    border: 0;
    border-right: 4px solid transparent;
    border-bottom: 8px solid var(--legend-marker-color);
    border-left: 4px solid transparent;
}

.legend-camera-symbol--circle {
    border-radius: 50%;
}

.legend-camera-group-symbol {
    display: grid;
    grid-template-columns: repeat(2, 6px);
    grid-template-rows: repeat(2, 6px);
    gap: 1px;
}

.legend-camera-group-symbol > span {
    border-radius: 50%;
}

.legend-label {
    flex: 0 0 auto;
    cursor: pointer;
}

.legend-info {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 17px;
    height: 17px;
    padding: 0;
    border: 0;
    background: transparent;
    color: #858585;
    cursor: help;
    font-size: 14px;
    margin-left: -5px;
}

.legend-info:hover,
.legend-info:focus-visible {
    color: #555;
}

.legend-info::after {
    position: absolute;
    z-index: 10;
    bottom: calc(100% + 7px);
    left: 50%;
    width: max-content;
    max-width: 240px;
    padding: 6px 8px;
    border-radius: 4px;
    background: #333;
    color: #fff;
    content: attr(data-tooltip);
    font: 12px/1.3 system-ui, sans-serif;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 3px);
    transition: opacity 120ms ease, transform 120ms ease;
}

.legend-info:hover::after,
.legend-info:focus-visible::after {
    opacity: 1;
    transform: translate(-50%, 0);
}

.legend-visual {
    display: grid;
    width: 17px;
    height: 17px;
    flex: 0 0 17px;
    place-items: center;
}

.legend-visual > * {
    grid-area: 1 / 1;
}

.legend-loader {
    display: none;
    box-sizing: border-box;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(68, 68, 68, 0.25);
    border-top-color: #555;
    border-radius: 50%;
    animation: legend-loading-spin 700ms linear infinite;
}

.legend-visual--loading .legend-icon,
.legend-visual--loading .legend-swatch {
    visibility: hidden;
}

.legend-visual--loading .legend-loader {
    display: block;
}

.legend-error {
    display: none;
    box-sizing: border-box;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #c62828;
    color: #fff;
    font: 700 11px/15px system-ui, sans-serif;
    text-align: center;
}

.legend-visual--error {
    position: relative;
    cursor: help;
}

.legend-visual--error .legend-icon,
.legend-visual--error .legend-swatch {
    visibility: hidden;
}

.legend-visual--error .legend-error {
    display: block;
}

.legend-visual--error::after {
    position: absolute;
    z-index: 10;
    bottom: calc(100% + 7px);
    left: 50%;
    width: max-content;
    max-width: 240px;
    padding: 6px 8px;
    border-radius: 4px;
    background: #333;
    color: #fff;
    content: attr(data-tooltip);
    font: 12px/1.3 system-ui, sans-serif;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 3px);
    transition: opacity 120ms ease, transform 120ms ease;
}

.legend-visual--error:hover::after,
.legend-visual--error:focus-visible::after {
    opacity: 1;
    transform: translate(-50%, 0);
}

.legend-visual--error:focus-visible {
    outline: 2px solid var(--ohaz-yellow);
    outline-offset: 2px;
    border-radius: 50%;
}

.legend-icon {
    width: 17px;
    height: 17px;
}

.legend-swatch {
    box-sizing: border-box;
    width: 17px;
    height: 17px;
    background: color-mix(in srgb, var(--legend-swatch-color) 24%, transparent);
    border: 2px solid var(--legend-swatch-color);
    border-radius: 3px;
}

@keyframes legend-loading-spin {
    to {
        transform: rotate(360deg);
    }
}

.legend-swatch--circle {
    width: 11px;
    height: 11px;
    flex: 0 0 11px;
    margin: 0 3px;
    background: var(--legend-swatch-color);
    border: 1.5px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(31, 41, 51, 0.28);
}

.legend-swatch--fill {
    border: 0;
    background: var(--legend-swatch-color);
}

.legend-swatch--burn-probability {
    background: linear-gradient(to right, #f2774f, #b83745);
}

.legend-swatch--fill.legend-swatch--dark-outline {
    border: 1px solid #2a2a2a;
}

.legend-division-filter {
    margin-top: 7px;
    padding-top: 8px;
    border-top: 1px solid #d8d8d8;
}

.legend-division-filter__row {
    display: grid;
    grid-template-columns: 1fr;
    align-items: center;
    gap: 2px;
    margin: 0;
    padding: 3px 0;
}

.legend-division-filter__label {
    color: #444;
    font-weight: 600;
}

.legend-division-filter__control {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    padding: 4px 22px 4px 6px;
    border: 1px solid #aaa;
    border-radius: 4px;
    background: #fff;
    color: #333;
    font: inherit;
}

.legend-division-filter__control:focus-visible {
    outline: 2px solid var(--ohaz-yellow);
    outline-offset: 1px;
}

.legend-division-filter__control:disabled {
    color: #666;
    cursor: not-allowed;
}

.legend-division-filter__status {
    min-height: 1.4em;
    margin: 3px 0 0;
    color: #555;
    font-size: 12px;
}

.legend-division-filter__status--error {
    color: #b42318;
    font-weight: 600;
}

@media (max-width: 520px) {
    .legend {
        font-size: 12px;
    }

}

@media (prefers-reduced-motion: reduce) {
    .legend-loader {
        animation: none;
    }
}
