/* ===== Left icon rail + feature popups (sidebar.js) ========================
   A persistent vertical rail on the left edge (Cloudflare / AI-tool style) that
   hosts feature icons; each opens a toggleable floating popup. First feature: the
   NPC filter builder (npc_filter.js). Palette matches the NPC card in npc.css. */

#app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 56px;
    z-index: 1500;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 0;
    background: rgba(8, 20, 13, 0.92);
    border-right: 1px solid rgba(46, 204, 113, 0.35);
    backdrop-filter: blur(4px);
}

.sb-brand {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    margin-bottom: 6px;
}
.sb-brand-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #6cf0a3, #1f8b50);
    box-shadow: 0 0 10px 2px rgba(46, 204, 113, 0.6);
}

.sb-icon {
    position: relative;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: #b8f5cf;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.sb-icon svg { width: 22px; height: 22px; display: block; }
.sb-icon:hover { background: rgba(46, 204, 113, 0.14); color: #eafff2; }
.sb-icon.active {
    background: linear-gradient(145deg, #14361f, #0c1f12);
    border-color: #2ecc71;
    color: #eafff2;
}
.sb-icon.disabled, .sb-icon:disabled { opacity: 0.4; cursor: default; }

.sb-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    box-sizing: border-box;
    border-radius: 8px;
    background: #2ecc71;
    color: #06150c;
    font: 700 10px/16px 'Georgia', serif;
    text-align: center;
}

/* ---- feature popup ------------------------------------------------------- */
.sb-popup {
    position: fixed;
    top: 64px;
    left: 66px;
    z-index: 1500;
    width: 340px;
    max-width: calc(100vw - 78px);
    max-height: calc(100vh - 84px);
    display: flex;
    flex-direction: column;
    background: rgba(12, 31, 18, 0.98);
    color: #eaf7ee;
    border: 1px solid rgba(46, 204, 113, 0.6);
    border-radius: 10px;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
    font-family: 'Georgia', serif;
    overflow: hidden;
}
.sb-popup-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(46, 204, 113, 0.25);
}
.sb-popup-title { font-weight: 700; font-size: 14px; flex: 1 1 auto; }
.sb-popup-close {
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #b8f5cf;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}
.sb-popup-close:hover { background: rgba(46, 204, 113, 0.15); color: #fff; }
.sb-popup-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 10px 12px; }

/* ---- filter builder (npc_filter.js) -------------------------------------- */
.npcf-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.npcf-count { flex: 1 1 auto; font-size: 13px; font-weight: 700; color: #7fe0a8; }
.npcf-clear {
    border: 1px solid rgba(46, 204, 113, 0.4);
    background: transparent;
    color: #b8f5cf;
    font-size: 11px;
    border-radius: 6px;
    padding: 3px 8px;
    cursor: pointer;
}
.npcf-clear:hover { background: rgba(46, 204, 113, 0.15); color: #fff; }

.npcf-row {
    border: 1px solid rgba(46, 204, 113, 0.22);
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.02);
}
.npcf-row-top { display: flex; align-items: center; gap: 6px; }
.npcf-prop {
    flex: 1 1 auto;
    min-width: 0;
    background: #0c1f12;
    color: #eaf7ee;
    border: 1px solid rgba(46, 204, 113, 0.4);
    border-radius: 6px;
    padding: 5px 6px;
    font-family: inherit;
    font-size: 12px;
}
.npcf-del {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #b8f5cf;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
}
.npcf-del:hover { background: rgba(231, 76, 60, 0.25); color: #fff; }
.npcf-row-input { margin-top: 8px; }

/* numeric min/max */
.npcf-num { display: flex; gap: 8px; }
.npcf-num-lbl { flex: 1 1 0; display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: #9fd9b6; }
.npcf-num-input {
    width: 100%;
    box-sizing: border-box;
    background: #0c1f12;
    color: #fff;
    border: 1px solid rgba(46, 204, 113, 0.4);
    border-radius: 6px;
    padding: 5px 6px;
    font-family: inherit;
    font-size: 12px;
}

/* include/exclude + any/all segmented controls */
.npcf-modes { display: flex; gap: 6px; margin-bottom: 7px; flex-wrap: wrap; }
.npcf-seg { display: inline-flex; border: 1px solid rgba(46, 204, 113, 0.4); border-radius: 6px; overflow: hidden; }
.npcf-seg-btn {
    border: none;
    background: transparent;
    color: #b8f5cf;
    font: 600 11px 'Georgia', serif;
    padding: 4px 10px;
    cursor: pointer;
}
.npcf-seg-btn.on { background: #2ecc71; color: #06150c; }
.npcf-anyall .npcf-seg-btn.on { background: #3aa6ff; color: #03121f; }

/* chips (selected values) + small toggle chips */
.npcf-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.npcf-chips.small { margin-top: 2px; }
.npcf-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    max-width: 100%;
    background: rgba(46, 204, 113, 0.16);
    border: 1px solid rgba(46, 204, 113, 0.45);
    border-radius: 12px;
    padding: 2px 4px 2px 7px;
    font-size: 11px;
}
.npcf-chip-t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.npcf-chip-x {
    border: none;
    background: transparent;
    color: #cfe6d8;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
}
.npcf-chip-x:hover { color: #fff; }
.npcf-chip-toggle {
    border: 1px solid rgba(46, 204, 113, 0.4);
    background: transparent;
    color: #b8f5cf;
    border-radius: 12px;
    padding: 3px 9px;
    font-size: 11px;
    cursor: pointer;
}
.npcf-chip-toggle.on { background: #2ecc71; color: #06150c; border-color: #2ecc71; }

/* big-set search + results */
.npcf-search {
    width: 100%;
    box-sizing: border-box;
    margin-top: 6px;
    background: #0c1f12;
    color: #fff;
    border: 1px solid rgba(46, 204, 113, 0.4);
    border-radius: 6px;
    padding: 6px 8px;
    font-family: inherit;
    font-size: 12px;
}
.npcf-results {
    margin-top: 4px;
    max-height: 190px;
    overflow: hidden auto;       /* clip horizontally, scroll vertically */
    position: relative;          /* contain any absolutely-positioned descendant (defensive
                                    against the global img{position:absolute}) so option icons
                                    can never paint over the controls below the box */
    border: 1px solid rgba(46, 204, 113, 0.3);
    border-radius: 6px;
    background: #0a1a10;
}
.npcf-res {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    text-align: left;
    border: none;
    border-bottom: 1px solid rgba(46, 204, 113, 0.12);
    background: transparent;
    color: #eaf7ee;
    padding: 5px 8px;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
}
.npcf-res:hover { background: rgba(46, 204, 113, 0.16); }
.npcf-res-empty { padding: 7px 8px; font-size: 12px; color: #9fd9b6; opacity: 0.8; }
/* position:static overrides the global `img { position:absolute }` (base.css, for the
   draggable map markers) — otherwise icons leave the flow and paint over the name's
   first letters. Static = in flow → sits beside the name and scrolls with its row. */
.npcf-opt-icon { width: 18px; height: 18px; flex: 0 0 auto; position: static; cursor: inherit; object-fit: contain; border-radius: 2px; background: rgba(0, 0, 0, 0.25); }

.npcf-add {
    width: 100%;
    border: 1px dashed rgba(46, 204, 113, 0.5);
    background: transparent;
    color: #7fe0a8;
    border-radius: 8px;
    padding: 8px;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
}
.npcf-add:hover:not(:disabled) { background: rgba(46, 204, 113, 0.12); color: #eafff2; }
.npcf-add:disabled { opacity: 0.5; cursor: default; }
.npcf-tip { margin-top: 8px; font-size: 11px; color: #9fd9b6; opacity: 0.8; line-height: 1.35; }
.npcf-res-note { padding: 6px 8px; font-size: 11px; color: #9fd9b6; opacity: 0.75; }

/* ===== v2: AND/OR groups, presets, saved filters ========================== */

/* Presets (collapsible) */
.npcf-presets, .npcf-saved { margin-bottom: 10px; }
.npcf-presets > summary, .npcf-saved > summary {
    cursor: pointer;
    font: 700 12px 'Georgia', serif;
    color: #7fe0a8;
    list-style: none;
    padding: 4px 0;
    user-select: none;
}
.npcf-presets > summary::-webkit-details-marker,
.npcf-saved > summary::-webkit-details-marker { display: none; }
.npcf-presets > summary::before, .npcf-saved > summary::before { content: '▸ '; font-size: 9px; }
.npcf-presets[open] > summary::before, .npcf-saved[open] > summary::before { content: '▾ '; }
.npcf-preset-list { display: flex; flex-direction: column; gap: 5px; margin-top: 4px; }
.npcf-preset {
    text-align: left;
    border: 1px solid rgba(46, 204, 113, 0.3);
    background: rgba(46, 204, 113, 0.06);
    border-radius: 7px;
    padding: 6px 8px;
    cursor: pointer;
    font-family: inherit;
}
.npcf-preset:hover { background: rgba(46, 204, 113, 0.16); }
.npcf-preset b { display: block; color: #eafff2; font-size: 12px; }
.npcf-preset span { display: block; color: #9fd9b6; font-size: 11px; }

/* top-level group join */
.npcf-top { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; font-size: 12px; }
.npcf-top-lbl { color: #cfe6d8; }

/* a group box; condition rows live inside it (so drop the per-row border) */
.npcf-group {
    border: 1px solid rgba(46, 204, 113, 0.45);
    border-radius: 9px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.02);
}
.npcf-group-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.npcf-group.collapsed .npcf-group-head { margin-bottom: 0; }
.npcf-group .npcf-seg { font-size: 11px; }
.npcf-group-del {
    width: 24px; height: 24px;
    border: none; border-radius: 6px;
    background: transparent; color: #b8f5cf;
    font-size: 17px; line-height: 1; cursor: pointer; flex: 0 0 auto;
}
.npcf-group-del:hover { background: rgba(231, 76, 60, 0.25); color: #fff; }
.npcf-group .npcf-row { border: none; background: transparent; padding: 0; margin: 0; }

/* collapsible group header: caret + editable name + summary */
.npcf-group-toggle {
    flex: 0 0 auto;
    width: 20px; height: 20px; padding: 0;
    border: none; background: transparent;
    color: #7fe0a8; font-size: 11px; line-height: 1; cursor: pointer;
}
.npcf-group-name {
    flex: 1 1 auto; min-width: 0;
    background: transparent; border: none; border-bottom: 1px solid transparent;
    color: #eafff2; font: 700 12px 'Georgia', serif; padding: 2px;
}
.npcf-group-name:hover { border-bottom-color: rgba(46, 204, 113, 0.3); }
.npcf-group-name:focus { outline: none; border-bottom-color: #2ecc71; }
.npcf-group-name::placeholder { color: #7fe0a8; opacity: 0.7; font-weight: 700; }
.npcf-group-sum { flex: 0 0 auto; font-size: 11px; color: #9fd9b6; opacity: 0.8; }
.npcf-group:not(.collapsed) .npcf-group-sum { display: none; }
.npcf-group-joinrow { margin-bottom: 7px; }

/* AND/OR connector between conditions inside a group */
.npcf-conn {
    font: 700 10px 'Georgia', serif;
    letter-spacing: 0.08em;
    color: #7fe0a8;
    opacity: 0.8;
    text-align: center;
    margin: 5px 0;
}
/* OR/AND divider between groups */
.npcf-or-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 8px 0;
    font: 700 11px 'Georgia', serif;
    letter-spacing: 0.1em;
    color: #ffd27a;
}
.npcf-or-divider::before, .npcf-or-divider::after {
    content: '';
    flex: 1 1 auto;
    height: 1px;
    background: rgba(255, 210, 122, 0.4);
}

.npcf-add-cond {
    margin-top: 8px;
    width: 100%;
    border: 1px dashed rgba(46, 204, 113, 0.45);
    background: transparent;
    color: #7fe0a8;
    border-radius: 7px;
    padding: 6px;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
}
.npcf-add-cond:hover { background: rgba(46, 204, 113, 0.12); }
.npcf-add-group {
    width: 100%;
    margin-top: 10px;
    border: 1px dashed rgba(255, 210, 122, 0.6);
    background: transparent;
    color: #ffd27a;
    border-radius: 8px;
    padding: 8px;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
}
.npcf-add-group:hover:not(:disabled) { background: rgba(255, 210, 122, 0.12); }
.npcf-add-group:disabled { opacity: 0.5; cursor: default; }

/* saved filters */
.npcf-save-row { display: flex; gap: 6px; margin: 4px 0 8px; }
.npcf-save-name {
    flex: 1 1 auto; min-width: 0;
    background: #0c1f12; color: #fff;
    border: 1px solid rgba(46, 204, 113, 0.4);
    border-radius: 6px; padding: 5px 7px;
    font-family: inherit; font-size: 12px;
}
.npcf-save-btn, .npcf-export, .npcf-import {
    border: 1px solid rgba(46, 204, 113, 0.45);
    background: rgba(46, 204, 113, 0.1);
    color: #eafff2;
    border-radius: 6px; padding: 5px 10px;
    font-family: inherit; font-size: 12px; cursor: pointer;
}
.npcf-save-btn:hover, .npcf-export:hover, .npcf-import:hover { background: rgba(46, 204, 113, 0.22); }
.npcf-saved-list { display: flex; flex-direction: column; gap: 4px; }
.npcf-saved-item { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.npcf-saved-name { flex: 1 1 auto; min-width: 0; font-size: 12px; color: #eaf7ee; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.npcf-saved-load, .npcf-saved-del {
    border: 1px solid rgba(46, 204, 113, 0.4);
    background: transparent; color: #b8f5cf;
    border-radius: 6px; padding: 2px 8px;
    font-family: inherit; font-size: 11px; cursor: pointer;
}
.npcf-saved-load:hover { background: rgba(46, 204, 113, 0.16); color: #fff; }
.npcf-saved-del:hover { background: rgba(231, 76, 60, 0.25); color: #fff; border-color: rgba(231, 76, 60, 0.5); }
.npcf-saved-empty { font-size: 12px; color: #9fd9b6; opacity: 0.8; }
.npcf-save-io { display: flex; gap: 6px; margin-top: 8px; }
.npcf-save-io .npcf-export, .npcf-save-io .npcf-import { flex: 1 1 0; }

/* ---- mobile: rail stays thin, popup becomes a near-full-width sheet ------- */
@media (max-width: 576px) {
    #app-sidebar { width: 48px; }
    .sb-icon { width: 36px; height: 36px; }
    .sb-popup {
        left: 54px;
        top: 8px;
        width: auto;
        right: 8px;
        max-width: none;
        max-height: calc(100vh - 16px);
    }
}
