/* ═══════════════════════════════════════
   LEGEND — Custom Legend Panel
   ═══════════════════════════════════════ */

#customLegend { position: fixed; top: 30px; right: 20px; width: 240px; background: rgba(8,17,31,0.93); backdrop-filter: blur(32px) saturate(1.4); box-shadow: var(--shadow-md); z-index: 500; border-radius: var(--radius-md); overflow: hidden; font-family: 'Inter',-apple-system,sans-serif; display: none; flex-direction: column; max-height: 400px; transition: opacity .2s, max-height .3s var(--ease-out); border: 1px solid var(--border-default); }
#customLegend.legend-visible { display: flex; }
#customLegend.mobile-active  { display: flex !important; }

#customLegendHeader { padding: 9px 12px; background: rgba(56,189,248,0.04); color: var(--text-primary); cursor: grab; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-ghost); user-select: none; }
#customLegendHeader:active { cursor: grabbing; }
#customLegendHeader h3 { margin: 0; font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; background: linear-gradient(120deg, var(--accent-sky), var(--accent-blue)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.legend-controls { display: flex; gap: 6px; }
.legend-btn { cursor: pointer; background: transparent; border: none; color: var(--text-muted); font-size: 13px; line-height: 1; padding: 2px; border-radius: 4px; transition: all .15s; display: flex; align-items: center; justify-content: center; }
.legend-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.08); }
#customLegendContent { padding: 8px; overflow-y: auto; flex-grow: 1; }
#customLegendContent::-webkit-scrollbar { width: 3px; }
#customLegendContent::-webkit-scrollbar-thumb { background: rgba(56,189,248,0.22); border-radius: 3px; }
#customLegendContent .layer-name { white-space: normal !important; word-break: break-word; line-height: 1.3; }

.custom-layer-item { background: rgba(255,255,255,0.03); border-radius: 5px; padding: 7px 10px; margin-bottom: 4px; display: flex; align-items: center; color: var(--text-primary); font-size: 12px; font-weight: 500; border: 1px solid var(--border-ghost); transition: background .15s; }
.custom-layer-item:last-child { margin-bottom: 0; }
.custom-layer-item:hover { background: rgba(255,255,255,0.06); border-color: var(--border-subtle); }
.layer-color-dot { width: 8px; height: 8px; border-radius: 2px; margin-right: 10px; flex-shrink: 0; }
.layer-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#customLegend.minimized { height: 36px !important; max-height: 36px !important; width: 150px; }
#customLegend.minimized #customLegendContent { display: none; }
#customLegend.minimized #customLegendHeader { border-bottom: none; }

.smpg-cor-dot { cursor: pointer; width: 16px !important; height: 16px !important; border-radius: 4px !important; transition: all .2s; flex-shrink: 0; position: relative; }
.smpg-cor-dot:hover { transform: scale(1.15); }
.smpg-cor-dot.inactive { filter: grayscale(1) brightness(0.5); opacity: 0.4; border: 1px dashed rgba(255,255,255,.2) !important; box-shadow: none !important; }
.smpg-cor-dot.inactive::after { content: '✕'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 9px; color: rgba(255,255,255,.7); line-height: 1; }

/* Sublayer dot toggle */
.sublayer-dot { cursor: pointer; width: 16px !important; height: 16px !important; border-radius: 4px !important; transition: all .2s; flex-shrink: 0; position: relative; }
.sublayer-dot:hover { transform: scale(1.15); }
.sublayer-dot.inactive { filter: grayscale(1) brightness(0.5); opacity: 0.4; border: 1px dashed rgba(255,255,255,.2) !important; box-shadow: none !important; }
.sublayer-dot.inactive::after { content: '✕'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 9px; color: rgba(255,255,255,.7); line-height: 1; }

/* Side tab */
.side-tab { display: none; align-items: center; justify-content: center; pointer-events: auto !important; position: absolute !important; left: -30px !important; top: 50% !important; transform: translateY(-50%) !important; width: 30px !important; height: 56px !important; background: rgba(8,17,31,0.96) !important; border: 1px solid var(--border-default) !important; border-radius: 10px 0 0 10px !important; border-right: none !important; color: var(--accent-sky) !important; z-index: 5001 !important; cursor: pointer !important; }
.side-tab span { display: block !important; font-size: 18px !important; font-weight: bold !important; transition: transform .3s !important; }
#customLegend.mobile-active .side-tab span { transform: rotate(180deg) !important; }
#customLegend.mobile-active { display: flex !important; transform: translateX(0%) !important; pointer-events: auto !important; }
