            /* ---------- popovers / menus ---------- */
            .pop {
                position: fixed;
                z-index: 120;
                background: var(--pop-bg);
                border: 1px solid var(--line2);
                border-radius: 8px;
                box-shadow: var(--shadow);
                min-width: 220px;
                max-width: min(460px, calc(100vw - 16px));
                max-height: min(480px, calc(100vh - 100px));
                overflow: auto;
                padding: 6px;
            }
            .pop .ptitle {
                font-size: 11px;
                font-weight: 600;
                text-transform: uppercase;
                letter-spacing: 0.05em;
                color: var(--faint);
                padding: 6px 8px 4px;
            }
            .mi {
                display: flex;
                align-items: center;
                gap: 8px;
                width: 100%;
                text-align: left;
                padding: 7px 9px;
                border-radius: 6px;
                font-size: 13px;
            }
            .mi:hover {
                background: var(--hover);
            }
            .mi.danger {
                color: var(--danger-tx);
            }
            .mi.danger:hover {
                background: var(--danger-bg);
            }
            .mi .ic {
                width: 15px;
                opacity: 0.7;
                text-align: center;
                flex: 0 0 auto;
            }
            .mi .sub {
                margin-left: auto;
                color: var(--faint);
                font-size: 11px;
            }
            .mi.checked::after {
                content: "✓";
                margin-left: auto;
                color: var(--ok-tx);
                font-weight: 600;
            }
            .pop hr {
                border: 0;
                border-top: 1px solid var(--line);
                margin: 5px 4px;
            }
            .pop .formrow {
                display: flex;
                align-items: center;
                gap: 6px;
                padding: 4px 6px;
            }
            .pop label.flabel {
                font-size: 11.5px;
                color: var(--mut);
                font-weight: 500;
                display: block;
                padding: 6px 8px 2px;
            }
            .tin {
                width: 100%;
                border: 1px solid var(--line2);
                border-radius: 6px;
                padding: 6px 8px;
                font-size: 13px;
                background: var(--field-bg);
                color: var(--ink);
            }
            .tin:focus {
                border-color: var(--sel);
            }
            select.tin {
                appearance: auto;
                padding: 5px 6px;
            }
            .btn {
                border-radius: 6px;
                padding: 6px 12px;
                font-weight: 600;
                font-size: 12.5px;
                border: 1px solid var(--line2);
                background: var(--field-bg);
                color: var(--ink);
            }
            .btn:hover {
                background: var(--hover);
            }
            .btn.primary {
                background: var(--sel);
                color: var(--sel-tx);
                border-color: var(--sel);
            }
            .btn.primary:hover {
                opacity: 0.88;
            }
            .btn.lime {
                background: var(--accent);
                border-color: var(--accent-border);
                color: #10240a;
            }
            .btn.danger {
                color: var(--danger-tx);
                border-color: var(--danger-tx);
                background: transparent;
            }
            .btn.danger:hover {
                background: var(--danger-bg);
            }
            .btn[disabled] {
                opacity: 0.45;
                cursor: default;
            }
            .popfoot {
                display: flex;
                gap: 8px;
                justify-content: flex-end;
                padding: 8px 6px 4px;
                /* keep the action buttons reachable when a popover scrolls */
                position: sticky;
                bottom: -6px;
                background: var(--pop-bg);
                margin-top: 4px;
                border-top: 1px solid var(--line);
            }

            /* condition rows (filter/sort) */
            .cond {
                display: flex;
                align-items: center;
                gap: 6px;
                padding: 4px 6px;
            }
            .cond select.tin,
            .cond input.tin {
                width: auto;
            }
            .cond .c-conj {
                width: 74px;
                flex: 0 0 auto;
            }
            .cond .c-field {
                width: 130px;
            }
            .cond .c-op {
                width: 140px;
            }
            .cond .c-val {
                width: 130px;
                flex: 1;
            }
            .cond .x {
                width: 26px;
                height: 26px;
                border-radius: 6px;
                color: var(--mut);
                flex: 0 0 auto;
            }
            .cond .x:hover {
                background: var(--danger-bg);
                color: var(--danger-tx);
            }
            .addlink {
                display: inline-flex;
                gap: 6px;
                align-items: center;
                color: #3e4c5b;
                font-weight: 600;
                font-size: 12.5px;
                padding: 7px 9px;
                border-radius: 6px;
            }
            .addlink:hover {
                background: var(--hover);
            }

            /* switches (hide fields) */
            .sw {
                position: relative;
                width: 26px;
                height: 15px;
                border-radius: 999px;
                background: var(--line2);
                flex: 0 0 auto;
                transition: background 0.12s;
            }
            .sw::after {
                content: "";
                position: absolute;
                top: 2px;
                left: 2px;
                width: 11px;
                height: 11px;
                border-radius: 50%;
                background: #fff;
                transition: left 0.12s;
            }
            .mi.on .sw {
                background: var(--ok-tx);
            }
            .mi.on .sw::after {
                left: 13px;
            }

            /* type picker */
            .typegrid {
                display: grid;
                grid-template-columns: 1fr 1fr;
                gap: 2px;
                padding: 2px;
            }
            .typegrid .mi {
                padding: 6px 8px;
            }
            .choice-row {
                display: flex;
                align-items: center;
                gap: 6px;
                padding: 3px 6px;
            }
            .choice-row .swatch {
                width: 16px;
                height: 16px;
                border-radius: 4px;
                flex: 0 0 auto;
                cursor: pointer;
                border: 1px solid rgba(0, 0, 0, 0.08);
            }
            .choice-row input.tin {
                flex: 1;
            }

            /* ---------- modal ---------- */
            .overlay {
                position: fixed;
                inset: 0;
                background: rgba(8, 17, 26, 0.45);
                z-index: 200;
                display: grid;
                place-items: center;
                padding: 24px;
            }
            .modal {
                background: var(--paper);
                border-radius: 12px;
                box-shadow: var(--shadow);
                width: 600px;
                max-width: 100%;
                max-height: min(82vh, 760px);
                display: flex;
                flex-direction: column;
                overflow: hidden;
            }
            .modal .mhead {
                display: flex;
                align-items: center;
                gap: 8px;
                padding: 14px 18px;
                border-bottom: 1px solid var(--line);
            }
            .modal .mhead .mtitle {
                font-size: 16px;
                font-weight: 700;
                flex: 1;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
            .modal .mbody {
                padding: 14px 18px;
                overflow: auto;
            }
            .modal .mfoot {
                display: flex;
                gap: 8px;
                padding: 12px 18px;
                border-top: 1px solid var(--line);
                justify-content: flex-end;
            }
            .iconbtn {
                width: 28px;
                height: 28px;
                border-radius: 6px;
                display: grid;
                place-items: center;
                color: var(--mut);
            }
            .iconbtn:hover {
                background: var(--hover);
                color: var(--ink);
            }
            .frow {
                margin-bottom: 14px;
            }
            .frow .flab {
                display: flex;
                align-items: center;
                gap: 6px;
                font-size: 11.5px;
                font-weight: 600;
                color: var(--mut);
                margin-bottom: 5px;
                text-transform: none;
            }
            .frow .flab .ficon {
                width: 15px;
                height: 15px;
                display: grid;
                place-items: center;
                font-size: 9px;
                font-weight: 700;
                color: var(--faint);
                border: 1px solid var(--line2);
                border-radius: 4px;
            }
            .pickrow {
                display: flex;
                align-items: center;
                gap: 8px;
                padding: 8px 10px;
                border: 1px solid var(--line);
                border-radius: 8px;
                margin-bottom: 6px;
                cursor: pointer;
            }
            .pickrow:hover {
                border-color: var(--sel);
            }
            .pickrow.sel {
                border-color: var(--sel);
                box-shadow: inset 0 0 0 1px var(--sel);
            }
            .pickrow .pname {
                font-weight: 600;
                flex: 1;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
            .pickrow .psub {
                color: var(--faint);
                font-size: 12px;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                max-width: 45%;
            }
            .pickrow .check {
                color: var(--ok-tx);
                font-weight: 700;
                visibility: hidden;
            }
            .pickrow.sel .check {
                visibility: visible;
            }

            /* toast */
            #toast {
                position: fixed;
                bottom: 18px;
                left: 50%;
                transform: translateX(-50%);
                z-index: 400;
                background: var(--chrome);
                color: #fff;
                padding: 9px 16px;
                border-radius: 8px;
                font-weight: 500;
                box-shadow: var(--shadow);
                display: none;
                align-items: center;
                gap: 10px;
            }
            #toast.show {
                display: flex;
            }
            #toast .lime {
                color: var(--lime);
            }

            /* ---------- shortcuts panel ---------- */
            .shortcut-body {
                display: grid;
                grid-template-columns: 1fr 1fr;
                gap: 4px 28px;
            }
            .shortcut-head {
                grid-column: 1 / -1;
                font-size: 11px;
                font-weight: 700;
                text-transform: uppercase;
                letter-spacing: 0.05em;
                color: var(--faint);
                margin: 12px 0 4px;
            }
            .shortcut-head:first-child {
                margin-top: 0;
            }
            .shortcut-row {
                display: flex;
                align-items: center;
                justify-content: space-between;
                gap: 12px;
                padding: 4px 0;
            }
            .shortcut-desc {
                color: var(--ink);
                font-size: 12.5px;
            }
            .shortcut-kbd {
                font-family: ui-monospace, Menlo, monospace;
                font-size: 11px;
                background: var(--field-bg);
                border: 1px solid var(--line2);
                border-bottom-width: 2px;
                border-radius: 5px;
                padding: 2px 7px;
                color: var(--mut);
                white-space: nowrap;
                flex: 0 0 auto;
            }

            /* ---------- find & replace ---------- */
            .findpanel {
                position: fixed;
                top: 96px;
                right: 16px;
                z-index: 70;
                display: flex;
                align-items: center;
                gap: 6px;
                flex-wrap: wrap;
                background: var(--pop-bg);
                border: 1px solid var(--line2);
                border-radius: 10px;
                box-shadow: var(--shadow);
                padding: 8px 10px;
                max-width: calc(100vw - 32px);
            }
            .findpanel .find-label {
                font-weight: 600;
                font-size: 12px;
                color: var(--mut);
                margin-right: 2px;
            }
            .findpanel input.tin {
                width: 140px;
            }
            .findpanel select.tin {
                width: auto;
            }
            .findpanel .find-count {
                font-size: 12px;
                color: var(--faint);
                min-width: 64px;
                text-align: center;
            }
            .findpanel .find-btn {
                width: 26px;
                height: 26px;
                border-radius: 6px;
                border: 1px solid var(--line2);
                background: var(--field-bg);
                color: var(--ink);
                font-size: 15px;
                line-height: 1;
            }
            .findpanel .find-btn:hover {
                background: var(--hover);
            }
            .findpanel .btn {
                padding: 5px 10px;
            }

