.modern-filters {
    --panel-gap: 24px;
    --panel-radius: 12px;
    --panel-border: #dcdcde;
    --panel-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    --panel-shadow-hover: 0 12px 30px rgba(15, 23, 42, 0.09);
    --surface-muted: #f6f7f7;
    --surface-soft: #fbfbfc;
    --text-strong: #1d2327;
    --text-muted: #50575e;
    --line-soft: #e7eaee;
    --accent-blue: #2271b1;
    --accent-blue-dark: #135e96;
    --accent-blue-soft: #eff6ff;
    --accent-gold: #f59e0b;
}

.modern-filters .wp-heading-inline {
    color: var(--text-strong);
}

.modern-filters .button-primary {
    background: var(--accent-blue) !important;
    border-color: var(--accent-blue) !important;
    color: #fff !important;
    border-radius: 6px !important;
    box-shadow: 0 2px 8px rgba(34, 113, 177, 0.18) !important;
    font-weight: 600 !important;
}

.modern-filters .button-primary:hover {
    background: var(--accent-blue-dark) !important;
    border-color: var(--accent-blue-dark) !important;
}

.modern-filters .button-link-delete {
    color: #b32d2e !important;
}

.modern-filters .postbox {
    border: 1px solid var(--panel-border) !important;
    border-radius: var(--panel-radius);
    box-shadow: var(--panel-shadow) !important;
    overflow: hidden;
    background: #fff;
    margin-bottom: 0;
}

.modern-filters .postbox:hover {
    box-shadow: var(--panel-shadow-hover) !important;
}

.modern-filters .postbox-header {
    background: linear-gradient(180deg, #ffffff 0%, #fbfbfc 100%) !important;
    border-bottom: 1px solid var(--line-soft) !important;
    padding: 18px 22px !important;
}

.modern-filters .postbox-header h2 {
    margin: 0 !important;
    padding: 0 !important;
    font-size: 16px !important;
    font-weight: 700 !important;
    color: var(--text-strong) !important;
}

.modern-filters .inside {
    padding: 22px !important;
}

.modern-filters .page-shell {
    display: grid;
    grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
    gap: var(--panel-gap);
    align-items: start;
}

.modern-filters .page-intro {
    margin-bottom: 24px;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
}

.modern-filters .page-intro p {
    margin: 6px 0 0 0;
    color: var(--text-muted);
    font-size: 14px;
    max-width: 720px;
}

.modern-filters .presets-panel .inside {
    padding: 12px !important;
    overflow: hidden auto;
}

.modern-filters #presets-panel {
    position: sticky;
    top: 72px;
    max-height: calc(100vh - 96px);
    display: flex;
    flex-direction: column;
}

.modern-filters #presets-panel .inside {
    flex: 1;
    min-height: 0;
}

.modern-filters #filter-groups-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.modern-filters #filter-groups-list li {
    position: relative;
    border: 1px solid transparent;
    background: #fff;
    border-radius: 10px;
    padding: 13px 14px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    color: var(--text-strong);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.modern-filters .filter-group-link {
    min-width: 0;
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    color: inherit;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.modern-filters .filter-group-name {
    min-width: 0;
}

.modern-filters .filter-group-link:hover,
.modern-filters .filter-group-link:focus {
    color: var(--accent-blue);
    text-decoration: none;
}

.modern-filters #filter-groups-list li:hover {
    background: var(--surface-soft);
    border-color: var(--line-soft);
    transform: translateY(-1px);
}

.modern-filters #filter-groups-list li.active {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-color: #60a5fa;
    color: #0f3d62;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.16);
    transform: translateY(-1px);
}

.modern-filters #filter-groups-list li.active .badge {
    color: #1d4ed8;
    border-color: #93c5fd;
    background:
        linear-gradient(135deg, rgba(255,255,255,.78) 0 12%, rgba(255,255,255,0) 13%),
        linear-gradient(145deg, #dbeafe 0%, #bfdbfe 52%, #93c5fd 100%);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.9), 0 8px 18px rgba(37, 99, 235, .22);
}

@media (min-width: 961px) {
    .modern-filters #filter-groups-list li.active::after {
        content: "";
        position: absolute;
        top: 50%;
        right: -18px;
        transform: translateY(-50%);
        border-top: 10px solid transparent;
        border-bottom: 10px solid transparent;
        border-left: 14px solid #60a5fa;
        filter: drop-shadow(0 4px 6px rgba(37, 99, 235, 0.18));
        pointer-events: none;
    }
}

.modern-filters .badge {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 54px;
    min-height: 38px;
    padding: 7px 11px 9px;
    border-radius: 12px;
    border: 1px solid #b8bdc2;
    border-top-color: #f6f7f8;
    border-bottom-color: #8e949a;
    background:
        linear-gradient(135deg, rgba(255,255,255,.7) 0 12%, rgba(255,255,255,0) 13%),
        linear-gradient(225deg, rgba(255,255,255,.55) 0 12%, rgba(255,255,255,0) 13%),
        linear-gradient(315deg, rgba(125,132,139,.22) 0 16%, rgba(125,132,139,0) 17%),
        linear-gradient(45deg, rgba(125,132,139,.18) 0 16%, rgba(125,132,139,0) 17%),
        linear-gradient(180deg, #f3f4f5 0%, #d4d8dc 100%);
    color: #4b5560;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.05;
    text-align: center;
    box-shadow:
        inset 0 2px 3px rgba(255,255,255,.92),
        inset 3px 0 3px rgba(255,255,255,.42),
        inset -4px 0 4px rgba(95,103,111,.18),
        inset 0 -5px 6px rgba(83,90,98,.23),
        0 3px 0 #9aa0a6,
        0 7px 11px rgba(15,23,42,.2);
    text-shadow: 0 1px 0 rgba(255,255,255,.8);
    transform: translateY(-2px);
}

.modern-filters .replacement-plain-text {
    font-family: inherit;
    font-style: normal;
    font-weight: 400;
    letter-spacing: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.modern-filters .active .badge {
    border-color: #9fc7fb;
    border-top-color: #f8fbff;
    border-bottom-color: #6f9fe4;
    background:
        linear-gradient(135deg, rgba(255,255,255,.78) 0 12%, rgba(255,255,255,0) 13%),
        linear-gradient(225deg, rgba(255,255,255,.62) 0 12%, rgba(255,255,255,0) 13%),
        linear-gradient(315deg, rgba(37,99,235,.16) 0 16%, rgba(37,99,235,0) 17%),
        linear-gradient(45deg, rgba(37,99,235,.12) 0 16%, rgba(37,99,235,0) 17%),
        linear-gradient(180deg, #eff6ff 0%, #d6e7ff 100%);
    color: #1d4ed8;
    box-shadow:
        inset 0 2px 3px rgba(255,255,255,.95),
        inset 3px 0 3px rgba(255,255,255,.45),
        inset -4px 0 4px rgba(37,99,235,.12),
        inset 0 -5px 6px rgba(37,99,235,.16),
        0 3px 0 #7fb0f2,
        0 7px 12px rgba(37,99,235,.22);
}

.modern-filters .panel-footer {
    border-top: 1px solid var(--line-soft);
    padding: 16px;
    background: var(--surface-soft);
    display: grid;
    gap: 10px;
}

.modern-filters .editor-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 18px;
}

.modern-filters .editor-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    color: var(--text-strong);
}

.modern-filters .editor-summary {
    background: linear-gradient(135deg, #eff6ff 0%, #f8fbff 100%);
    border: 1px solid #dbeafe;
    border-left: 4px solid var(--accent-blue);
    border-radius: 10px;
    padding: 14px 16px;
    font-size: 13px;
    color: #1e3a5f;
    margin-bottom: 18px;
}

.modern-filters .editor-summary ul {
    margin: 8px 0 0 0;
    padding-left: 18px;
}

.modern-filters .stack-grid {
    display: grid;
    gap: var(--panel-gap);
}

.modern-filters .editor-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--panel-gap);
    align-items: start;
}

.modern-filters .field-stack {
    display: grid;
    gap: var(--panel-gap);
}

.modern-filters .setting-section + .setting-section {
    border-top: 1px solid var(--line-soft);
    margin-top: 18px;
    padding-top: 18px;
}

.modern-filters .setting-section-title {
    margin: 0 0 8px 0;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: #6b7280;
}

.modern-filters .setting-description,
.modern-filters .helper-text {
    margin: 0 0 12px 0;
    font-size: 13px;
    color: var(--text-muted);
}

.modern-filters .checkbox-stack {
    display: grid;
    gap: 12px;
}

.modern-filters .checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 14px;
    color: var(--text-strong);
    cursor: pointer;
    line-height: 1.45;
}

.modern-filters .checkbox-row input {
    margin-top: 2px;
}

.modern-filters .help-tip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 6px;
    border-radius: 50%;
    border: 1px solid #c3c4c7;
    background: #f6f7f7;
    color: #50575e;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    cursor: help;
    vertical-align: text-bottom;
}

.modern-filters .help-tip-popover {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    z-index: 10020;
    display: none;
    width: min(360px, calc(100vw - 48px));
    padding: 10px 12px;
    border-radius: 8px;
    background: #1f2937;
    color: #f9fafb;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.28);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.35;
    text-align: left;
    text-transform: none;
    transform: translateX(-50%);
    pointer-events: none;
}

.modern-filters .help-tip-popover::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 100%;
    border: 6px solid transparent;
    border-top-color: #1f2937;
    transform: translateX(-50%);
}

.modern-filters .help-tip:hover .help-tip-popover,
.modern-filters .help-tip:focus .help-tip-popover,
.modern-filters .help-tip:focus-within .help-tip-popover {
    display: block;
}

.modern-filters .select-field,
.modern-filters .text-field,
.modern-filters textarea,
.modern-filters #group_signature {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    border: 1px solid #c3c4c7 !important;
    border-radius: 8px !important;
    box-shadow: none !important;
    background: #fff;
}

.modern-filters .select-field,
.modern-filters .text-field,
.modern-filters textarea {
    min-height: 42px;
    padding: 9px 12px !important;
    font-size: 14px !important;
}

.modern-filters .text-field:focus,
.modern-filters textarea:focus,
.modern-filters .select-field:focus,
.modern-filters #group_signature:focus {
    outline: none !important;
    border-color: var(--accent-blue) !important;
    box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.12) !important;
}

.modern-filters .tasks-box {
    max-height: 180px;
    overflow-y: auto;
    padding: 10px;
    background: var(--surface-soft);
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modern-filters .task-binding-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    line-height: 1.3;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.modern-filters .task-binding-row:hover {
    background: #fff;
    border-color: #dbeafe;
}

.modern-filters .task-binding-row.is-checked {
    background: #eff6ff;
    border-color: #93c5fd;
    box-shadow: inset 3px 0 0 var(--accent-blue), 0 2px 8px rgba(34, 113, 177, 0.08);
    color: #0f3d62;
    font-weight: 600;
}

.modern-filters .task-binding-row input {
    flex: 0 0 auto;
}

.modern-filters .task-binding-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modern-filters .dictionary-table-wrap {
    border: 1px solid var(--line-soft);
    border-radius: 10px;
    overflow: hidden;
    background: var(--surface-soft);
}

.modern-filters table.striped > tbody > tr:nth-of-type(odd) {
    background-color: #fafbfc;
}

.modern-filters table td,
.modern-filters table th {
    padding: 12px 15px !important;
    color: #374151;
    border-bottom: 1px solid var(--line-soft) !important;
}

.modern-filters .fr-form {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) max-content;
    gap: 10px;
    align-items: stretch;
}

.modern-filters .fr-form > * {
    min-width: 0;
    box-sizing: border-box;
}

.modern-filters .fr-form .button {
    min-height: 42px;
    height: auto;
    padding-left: 18px;
    padding-right: 18px;
}

.modern-filters .note-card {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-left: 4px solid var(--accent-gold);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 12px;
    color: #7c5b12;
}

.modern-filters .toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.modern-filters #group_signature {
    min-height: 110px;
    padding: 12px;
    overflow-y: auto;
}

.modern-filters .signature-rotation {
    background: var(--surface-soft);
    border: 1px solid var(--line-soft);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 12px;
    color: var(--text-muted);
}

.modern-filters .signature-rotation code,
.modern-filters .note-card code {
    background: rgba(255, 255, 255, 0.7);
    padding: 1px 5px;
    border-radius: 4px;
}

.modern-filters .modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.modern-filters .modal-card {
    width: min(340px, calc(100vw - 32px));
    max-width: calc(100vw - 32px);
    box-sizing: border-box;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.25);
    padding: 22px;
}

.modern-filters #link-modal-url {
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.modern-filters .empty-state {
    border: 1px dashed #c3c4c7;
    border-radius: 12px;
    padding: 28px 24px;
    text-align: center;
    background: linear-gradient(180deg, #fff 0%, #f8fafc 100%);
    color: var(--text-muted);
    margin-top: var(--panel-gap);
}

.modern-filters .empty-state h3 {
    margin: 0 0 6px 0;
    color: var(--text-strong);
    font-size: 18px;
}

.modern-filters .presets-drawer-toggle,
.modern-filters .presets-drawer-backdrop {
    display: none;
}

@media (max-width: 1180px) {
    .modern-filters .page-shell {
        grid-template-columns: minmax(240px, 280px) minmax(0, 1fr);
    }

    .modern-filters .editor-grid {
        grid-template-columns: 1fr;
    }

    .modern-filters #presets-panel {
        position: sticky;
    }
}

@media (max-width: 960px) {
    .modern-filters .page-shell {
        grid-template-columns: 1fr;
    }

    .modern-filters .presets-drawer-toggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: max-content;
    }

    .modern-filters .presets-drawer-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.42);
        z-index: 9998;
    }

    .modern-filters.presets-drawer-open .presets-drawer-backdrop {
        display: block;
    }

    .modern-filters #presets-panel {
        position: fixed;
        top: 46px;
        left: 0;
        bottom: 0;
        width: min(340px, calc(100vw - 32px));
        max-height: none;
        z-index: 9999;
        border-radius: 0 10px 10px 0;
        transform: translateX(-105%);
        transition: transform 0.2s ease;
    }

    .modern-filters.presets-drawer-open #presets-panel {
        transform: translateX(0);
    }
}

@media (max-width: 782px) {
    .modern-filters .page-intro,
    .modern-filters .editor-header {
        flex-direction: column;
        align-items: stretch;
    }

    .modern-filters .fr-form {
        grid-template-columns: 1fr;
    }

    .modern-filters .fr-form .button {
        width: 100%;
    }

    .modern-filters .inside {
        padding: 18px !important;
    }

    .modern-filters .postbox-header {
        padding: 16px 18px !important;
    }

    .modern-filters .editor-header h2 {
        font-size: 21px;
    }
}

.modern-filters .filter-rules-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--panel-gap);
    align-items: stretch;
}

.modern-filters .selected-filter-context {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: var(--panel-gap);
    padding: 12px 14px;
    border: 1px solid #bfdbfe;
    border-left: 4px solid #2563eb;
    border-radius: 10px;
    background: linear-gradient(135deg, #eff6ff 0%, #ffffff 100%);
    color: #0f172a;
    box-shadow: 0 6px 18px rgba(37, 99, 235, 0.08);
}

.modern-filters .selected-filter-label {
    color: #475569;
    font-size: 13px;
}

.modern-filters .selected-filter-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 3px 9px;
    color: #1d4ed8;
    background: #dbeafe;
    font-size: 12px;
    font-weight: 700;
}

.modern-filters .filter-rule-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.modern-filters .filter-rule-card .inside {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.modern-filters .rules-textarea {
    min-height: 260px;
    resize: vertical;
    font-family: Consolas, Monaco, monospace;
}

.modern-filters .filter-note {
    margin-top: 12px;
    background: #f8fafc;
    border: 1px solid var(--line-soft);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 12px;
    color: var(--text-muted);
}

@media (max-width: 1180px) {
    .modern-filters .filter-rules-grid {
        grid-template-columns: 1fr;
    }
}
